我想更换
$('#topspeed').change(function(){
有一个条件,类似下面的东西,但工作
if($("[id=topspeed]").is(":selected")){
怎么做?
答案如下:
$('select').change(function(){
if($(this).is('#topspeed'))
谢谢。
来自jQuery Docs
:selected选择器适用于<;选项>;元素确实如此不适用于复选框或无线电输入,
您似乎直接在select
元素上使用了这个。
你可以写这样的东西代替
if($('#topspeed option[value="1"]').is(":selected")) {
编辑
由于语法错误而无法工作
$('select').change(function () {
if ($(this).is('#topspeed') {
^------ Missing Closing brace
alert('Shrubs has been selected')
})
^------ Not supposed to be here
})
工作小提琴