Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Jquery中的字符串中删除子字符串_Javascript_Jquery_Asp.net - Fatal编程技术网

Javascript 从Jquery中的字符串中删除子字符串

Javascript 从Jquery中的字符串中删除子字符串,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我正在为复选框列表的click事件编写一个jQuery函数,当选中一个项目时,它将值存储在字符串中,当它未选中时,它将删除该字符串。我正在获取闭合标签文本,并将其插入字符串并从字符串中删除。我可以添加字符串,但无法删除它 这是我的密码: var currentage = ''; $('#<%=chk_ange.ClientID%> input:checkbox').click(function () { var str = $(this).next('label').tex

我正在为复选框列表的click事件编写一个jQuery函数,当选中一个项目时,它将值存储在字符串中,当它未选中时,它将删除该字符串。我正在获取闭合标签文本,并将其插入字符串并从字符串中删除。我可以添加字符串,但无法删除它

这是我的密码:

var currentage = '';

$('#<%=chk_ange.ClientID%> input:checkbox').click(function () {
    var str = $(this).next('label').text();
    if ($(this).is(':checked')) {
        if (currentage.indexOf($(this).next('label').text()) == -1) {
            currentage = currentage + str;
        }
        alert('checked' + currentage);
    }
    else {
        currentage.replace(str, "Hello");
        //currentage.replace(str, 'None');
        alert('unchecked' + currentage);
    } 
}
var currentage='';
$(“#输入:复选框”)。单击(函数(){
var str=$(this.next('label').text();
如果($(this).is(':checked')){
if(currentage.indexOf($(this).next('label').text())==-1){
currentage=currentage+str;
}
警报(“已检查”+当前日期);
}
否则{
currentage.replace(str,“Hello”);
//currentage.replace(str,'None');
警报(“未选中”+当前日期);
} 
}

我将这些值存储在一个全局变量中,以便在每次单击时比较值。

您必须将
replace
的结果分配回您的变量,如:

currentage = currentage.replace(str, "Hello");

请参阅:

您必须将
replace
的结果分配回变量,如下所示:

currentage = currentage.replace(str, "Hello");

请参阅:

您必须将
replace
的结果分配回变量,如下所示:

currentage = currentage.replace(str, "Hello");

请参阅:

您必须将
replace
的结果分配回变量,如下所示:

currentage = currentage.replace(str, "Hello");

请参阅:

您需要将
currentage.replace(str,“Hello”);
currentage
的结果相等。字符串是不可变的,因此
replace()
函数返回一个新修改的字符串

currentage = currentage.replace(str, "Hello");

您需要将
currentage.replace(str,“Hello”);
currentage
的结果相等。字符串是不可变的,因此
replace()
函数返回一个新修改的字符串

currentage = currentage.replace(str, "Hello");

您需要将
currentage.replace(str,“Hello”);
currentage
的结果相等。字符串是不可变的,因此
replace()
函数返回一个新修改的字符串

currentage = currentage.replace(str, "Hello");

您需要将
currentage.replace(str,“Hello”);
currentage
的结果相等。字符串是不可变的,因此
replace()
函数返回一个新修改的字符串

currentage = currentage.replace(str, "Hello");

哦,那是个错误,感谢快速反应解决了…有时它只是从视力上消失…@user2664298,是的,发生了:),你很好哦,那是个错误,感谢快速反应解决了…有时它只是从视力上消失…@user2664298,是的,发生了:),你很好哦那是个错误谢谢你的快速反应解决了…有时它只是从视力中消失…@user2664298,是的,发生了:),你很好哦那是个错误谢谢你的快速反应解决了…有时它只是从视力中消失…@user2664298,是的,发生了:),欢迎你