簡體   English   中英

新添加的選擇選項不顯示標題屬性

[英]Newly appended select options not displaying title attribute

我目前正在使用ajax將新選項附加到多選框,但是即使我試圖向它們添加標題屬性,它們似乎也沒有顯示。 有什么我想念的嗎?

在此處輸入圖片說明

這是在Coffeescript中完成的:

$.ajax(
        type: 'get'
        url: '/Filter/LookupClassification'
        data: ( term: inputVal )
        dataType: 'json'
        success: (response)->
            select = document.getElementById('getClassBox')
            select.options.length = 0

            $.each(response, (key, value)->
                option = $(
                    '<option/>'
                    'title': value.toUpperCase()
                    'value': key
                ).text(key + ' - ' + value.toUpperCase())

                $('#getClassBox').append(option)
            )

            $('#selectClassBox option').each((index, value)->
                val1 = $(value).val()
                if $('#getClassBox option').val() is val1
                    $('#getClassBox option[value=' + val1 + ']').remove()
            )
    )

<option>元素不能具有“ title”屬性。 參見規格。

編輯 -我的意思是,雖然可以根據需要添加“ title”屬性,但瀏覽器不會像<div><button>元素上的“ title”屬性那樣關注它。

再次編輯 -您可能也應該忽略它,因為盡管它不在HTML5規范中,但在某些瀏覽器中顯然支持<option>元素上的“ title”屬性。

您只需編寫以下代碼即可為下拉菜單添加選項:

select.options[select.options.length] = new Option(key + ' - ' + value.toUpperCase(), key);

不要為標題屬性而煩惱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM