鍍金池/ 問答/Python  HTML/ jquery選擇器出錯(cuò)

jquery選擇器出錯(cuò)

   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 ]
應(yīng)該如何處理

回答
編輯回答
憶當(dāng)年

引號(hào)問題

// $("[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);
2017年1月22日 05:17
編輯回答
艷骨

是不可以包含*號(hào)吧

2018年4月25日 14:33