0

以下がIE8で機能しないのに、他のすべてのブラウザーでは機能するのはなぜですか。

$(function () {

        //add binding to dropdowns
        $("#PersonsId").change(function () {
            $('option:selected', this).attr('selected', true).siblings().removeAttr('selected');
            //set value on hidden text field           
            if ($(this)[0].selectedIndex > 0) {                    
                $(this).parent().next().val($(this).find("option:selected").text());
            }
            else {
                $(this).parent().next().val("");
            }
        });
    });

たぶんこれは最善の解決策ではないので、これをどのように変更しますか?

4

1 に答える 1

1

この線

 $('option:selected', this).attr('selected', true).siblings().removeAttr('selected');

オプションを選択すると、残りのオプションはデフォルトで選択されていないため、必要ありません。非表示フィールドに値を設定するには、次のコードを使用します

$("input[type='hidden']").val($(this).val());

于 2012-09-14T11:43:13.000 に答える