0

我想换

$('#topspeed').change(function(){

有一个条件,如下所示,但工作

if($("[id=topspeed]").is(":selected")){ 

怎么做?

4

2 回答 2

0

来自 jQuery 文档

:selected 选择器适用于 <option> 元素它不适用于复选框或单选输入,

您似乎直接在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
})

工作小提琴

于 2013-06-23T03:27:52.370 回答
0

这是答案:

$('select').change(function(){
if($(this).is('#topspeed'))

谢谢你。

于 2013-06-23T13:41:50.740 回答