2

現在 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()
            )
    )
4

2 に答える 2

0

これを単純に記述して、ドロップダウンにオプションを追加できます。

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

タイトル属性は気にしないでください。

于 2013-04-25T15:03:55.213 に答える