3 回答
已采纳
橋本奈奈未
TA贡献436条经验 获得超108个赞
var arr = []; btn.onclick = (function() { var added = false; return function(){ var v = btn.value; if(added) { arr.splice(arr.indexOf(v),1); }else { arr.push(v); } added = !added; } })();
Mengyao_
TA贡献2条经验 获得超0个赞
var aInp = []; var vals = []; var englishName = []; // var count=0; //<%--4G基站工参(不含高铁)--%> $(".area_list .area_1").click(function(){ $(this).toggleClass("kind_btn") // 再次点击按钮回到原来样式 if($(this).hasClass("kind_btn")){ var val = $(this).val(); // console.log(val); var names = $(this).prop("name"); // console.log(names); var english = $(this).attr("aa"); aInp.push(names); vals.push(val); englishName.push(english); var Obj = ""; strs = ""; arr = ""; // console.log(aInp); // console.log(aInp.length); if(aInp.length>0){ for (var i = 0; i < aInp.length; i++){ Obj += aInp[i] + "," ; } } if(vals.length>0) { for (var i = 0; i < vals.length; i++) { strs += vals[i] + ","; } } if(englishName.length>0) { for (var i = 0; i < englishName.length; i++){ arr += englishName[i] + "," ; } } // console.log(Obj); var reg=/,$/gi;//此处是正则 去掉数组最后的小数点 str=Obj.replace(reg,""); strs=strs.replace(reg,""); arr=arr.replace(reg,""); console.log(str); console.log(strs); console.log(arr); }else{ alert("删除"); aInp.splice(str,1); vals.splice(strs,1); englishName.splice(arr,1); console.log(str) }
有什么问题吗
Mengyao_
TA贡献2条经验 获得超0个赞
var aInp = []; var vals = []; var englishName = []; // var count=0; //<%--4G基站工参(不含高铁)--%> $(".area_list .area_1").click(function(){ $(this).toggleClass("kind_btn") // 再次点击按钮回到原来样式 if($(this).hasClass("kind_btn")){ var val = $(this).val(); // console.log(val); var names = $(this).prop("name"); // console.log(names); var english = $(this).attr("aa"); aInp.push(names); vals.push(val); englishName.push(english); var Obj = ""; strs = ""; arr = ""; // console.log(aInp); // console.log(aInp.length); if(aInp.length>0){ for (var i = 0; i < aInp.length; i++){ Obj += aInp[i] + "," ; } } if(vals.length>0) { for (var i = 0; i < vals.length; i++) { strs += vals[i] + ","; } } if(englishName.length>0) { for (var i = 0; i < englishName.length; i++){ arr += englishName[i] + "," ; } } // console.log(Obj); var reg=/,$/gi;//此处是正则 去掉数组最后的小数点 str=Obj.replace(reg,""); strs=strs.replace(reg,""); arr=arr.replace(reg,""); console.log(str); console.log(strs); console.log(arr); }else{ alert("删除"); aInp.splice(str,1); vals.splice(strs,1); englishName.splice(arr,1); console.log(str) }
我是这样写的,但是有问题
添加回答
举报
0/150
提交
取消