jquery选择器出错

   var spvalue=$(this).text();
  $("[data-input="+spvalue+"]").prop("checked",true);

spvalue取值可能是 AP 4200或者6*180

jquery.min.js:2 Uncaught Error: Syntax error, unrecognized expression: [data-input=AP 5200 ]

Uncaught Error: Syntax error, unrecognized expression: [data-input=5*112 ]
应该如何处理

阅读 2.1k
2 个回答

引号问题

// $("[data-input=AP 5200]").prop("checked",true); →
$('[data-input="AP 5200"]').prop("checked",true);

// $("[data-input="+spvalue+"]").prop("checked",true); →
$('[data-input="'+spvalue+'"]').prop("checked",true);

是不可以包含*号吧

推荐问题