我生成了用于选择或取消选择我的数据的自定义复选框。我有2个自定义函数用于选择和取消选择数据。在select方法中,我需要传递2个变量,它是字段值。将特殊字符的动态字符串变量传递给JQuery函数
我的代码:
<span custom-checkbox="true"
is-checked="false"
name="id"
data-val="{this.id}"
on-select="DataSelect('{this.id+'\',\'' +this.name}')"
on-unselect="DataUnselect('{this.id}')" id="{this.id}">
</span>
function DataSelect(id, value){
console.log(id);
console.log(value);
//my code
}
function DataUnselect(id, value){
//my code
}
问题:
名称字段包含特殊字符,如引号( '')。以下是样本数据;
id = "1";
name= "hey'len";
在这里我得到了问题,由于报价(')。所以数据被操纵为;
DataSelect('1', 'hey'len')
,所以我就为 “未捕获的语法错误:缺少)后的参数列表”。
请帮我解决这个
试试这个name.replace( “\ ' ”G“,\\'”) –
请帮助方法本身进行更新。在html dataselect中 – Akhil
你能否提供一点信息。因为它看起来像不能单独使用jquery(在HTML中处理'{..}')。 –