jQuery按名称选择带有数组名称的单选按钮

时间:2019-11-23 10:08:12

标签: jquery

更改时我试图选择单选按钮,但出现错误

  

未捕获的错误:语法错误,无法识别的表达式:   [name = employment [employed]]

这是我的代码示例:

$('[name=employment[employed]]').change(function(){
    console.log('changed');
})

2 个答案:

答案 0 :(得分:1)

我知道了。只需添加两个反斜杠即可。

$('[name=employment\\[employed\\]]').change(function(){ 
    console.log('changed'); 
}) 

答案 1 :(得分:0)

下面的代码很有帮助。

$('[name=employment\\[employed\\]]').change(function(){ 
    console.log('changed'); 
})