HTML5 datalist tag is not populating in Safari

前端 未结 6 1873
栀梦
栀梦 2020-12-01 06:39

I have a datalist tag which allows my users to have a suggestion box. However, I\'ve noticed that this feature is not supported in safari. Is there a workaround to this issu

6条回答
  •  感情败类
    2020-12-01 07:17

    Further to what Mianto said regarding iamse7en's issue, in order to bind your datalist to a dynamic DIV (the example Mianto gave and then Moritz edited is hard-coded), change the following at line 51:

    function convert(input, datalist, listItems) {
        var fakeList = document.createElement('ul');
        var visibleItems = null;
        fakeList.id = listId;
        fakeList.className = LIST_CLASS;
        document.body.appendChild( fakeList );
    

    to:

    function convert(input, datalist, listItems) {
        var fakeList = document.createElement('ul');
        var visibleItems = null;
        fakeList.id = listId;
        fakeList.className = LIST_CLASS;
        input.parentNode.style.position = "relative";
        input.parentNode.appendChild( fakeList );
    

提交回复
热议问题