Using jquery to determine selected option causes “

2019-01-14 15:27发布

Probably missing something pretty obvious but I can't figure out what is going on. I am trying to use jquery to determine the currently selected option in a dropdown (See fiddle) but when I do something like the following I get a Warning in the (FF9) console.

var selectedValue=$('#testSelect option:selected').val();

Warning Message:

Warning: Use of attributes' specified attribute is deprecated. It always returns true.

Am I doing something wrong? Is this something I should be concerned with? Thanks in advance.

5条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-14 15:47

If the id #testSelect is your select name.

Get the value:

var selectedValue=$('#testSelect').attr('value');

Set the select value:

$('#testSelect').attr('value',your value);
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-14 15:50

can you use this code

<script type="text/javascript">
$(document).ready(function() {
$('select[id$=<%=DropDownList1.ClientID%>]').bind("keyup
change", function() {
if ($(this).val() != "")
$('#message').text("Text: " + $(this).
find(":selected").text()
+ ' Value: ' + $(this).val());
else
$('#message').text("");
});
});
</script>
查看更多
【Aperson】
4楼-- · 2019-01-14 15:54
$(document).on('change','select#FIELD_NAME', function() {
    alert('your selection was: '+$('select#FIELD_NAME').attr('value'));
    return false;
});

K.I.S.S. ...whenever it's possible ;-)

查看更多
Viruses.
5楼-- · 2019-01-14 15:57

Ask the select tag for it's value, it knows which one is selected and will use that tag for it's current value.

$('#testSelect').val()

Check it: http://jsfiddle.net/Ndzvm/1/

Sometimes it's simpler than you think it is :)

查看更多
Anthone
6楼-- · 2019-01-14 16:05

jquery is referencing the "specified" property on an Attr object, this is depreciated with Firefox 7, and always returns true. see https://developer.mozilla.org/En/DOM/Attr

i've raised a jquery ticket for this: http://bugs.jquery.com/ticket/11397

查看更多
登录 后发表回答