开发者

Finding $(this) selected value in jQuery

开发者 https://www.devze.com 2022-12-22 11:06 出处:网络
Can\'t work this out... I\'ve got a .change event handler for multiple select boxes.I need to find the selected value each time.I can\'t work out how to use .val with $(this).

Can't work this out...

I've got a .change event handler for multiple select boxes. I need to find the selected value each time. I can't work out how to use .val with $(this).

So here's my code:

$(document).ready(function(){
  $("select.className").change(function() {
开发者_StackOverflow
    //console.log($(this).val);
    //console.log($("option:selected",this).val);
  })
})

Both of the above return a function, and not the selected value I am looking for.

Any help would be great. Thanks.


Like everything else in jQuery, val is a function.
You need to call the function, like this: $(this).val().


.val is a method rather than a property. You will need to call it with parens:

//console.log($(this).val());
//console.log($("option:selected",this).val());
0

精彩评论

暂无评论...
验证码 换一张
取 消