首页 > 解决方案 > jquery按名称选择带有数组名称的单选按钮

问题描述

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

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

这是我的代码示例:

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

标签: jquery

解决方案


我想到了。只需添加两个反斜杠。

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

推荐阅读