function doCheck(obj)
{
var objvalue = obj.value;
var dm = theForm.default_method;
var dmvalue = theForm.default_method.value.toString();
if(obj.checked){
if( dm.value == ''){
dm.value = objvalue;
}else{
dm.value = dm.value +","+ objvalue ;
}
}else{
dmvalue.replace(/(,?)objvalue(,?)/,"$1");
theForm.default_method.value = dmvalue;
}
window.alert(dmvalue+':'+dm.value);
} <tr>
<td class="title">默认方法:<input type="hidden" name="default_method" value="<c:out value='${param.default_method}'/>" /></td>
<td>
<input type="checkbox" id="dmethod" name="dmethod" value="1" onclick="doCheck(this)" >查看
<input type="checkbox" id="dmethod" name="dmethod" value="2" onclick="doCheck(this)" >新增
<input type="checkbox" id="dmethod" name="dmethod" value="4" onclick="doCheck(this)" >修改
<input type="checkbox" id="dmethod" name="dmethod" value="8" onclick="doCheck(this)" >删除
<input type="checkbox" id="dmethod" name="dmethod" value="16" onclick="doCheck(this)" >批量删除
</td>
</tr>
dmvalue.replace(/(,?)objvalue(,?)/,"$1");的值并没有改变。
{
var objvalue = obj.value;
var dm = theForm.default_method;
var dmvalue = theForm.default_method.value.toString();
if(obj.checked){
if( dm.value == ''){
dm.value = objvalue;
}else{
dm.value = dm.value +","+ objvalue ;
}
}else{
dmvalue.replace(/(,?)objvalue(,?)/,"$1");
theForm.default_method.value = dmvalue;
}
window.alert(dmvalue+':'+dm.value);
} <tr>
<td class="title">默认方法:<input type="hidden" name="default_method" value="<c:out value='${param.default_method}'/>" /></td>
<td>
<input type="checkbox" id="dmethod" name="dmethod" value="1" onclick="doCheck(this)" >查看
<input type="checkbox" id="dmethod" name="dmethod" value="2" onclick="doCheck(this)" >新增
<input type="checkbox" id="dmethod" name="dmethod" value="4" onclick="doCheck(this)" >修改
<input type="checkbox" id="dmethod" name="dmethod" value="8" onclick="doCheck(this)" >删除
<input type="checkbox" id="dmethod" name="dmethod" value="16" onclick="doCheck(this)" >批量删除
</td>
</tr>
dmvalue.replace(/(,?)objvalue(,?)/,"$1");的值并没有改变。
alert(dmvalue);
dmvalue = dmvalue.replace(/(,?)objvalue(,?)/,"$1");
alert(dmvalue);
是判断值得是不是等于",objvalue,"的...
不是你想要的把值赋给中间的objvalue的效果...用var re=RegExp("(,?)"+objvalue+"(,?)")
试试
dmvalue.replace(/(,?)objvalue(,?)/,"$1");改成dmvalue = dmvalue.replace(/(,?)objvalue(,?)/,"$1");
<head>
<script type="text/javascript">
function change(sva)
{
str = "2,4,8,16";str.replace(new RegExp("(,?)"+sva+"(,?)"),"$1");
alert(str);
}
</script>
</head>
<body><input type="button" onclick="change(2)"
value="button" /><br>
<input type="text" name="vvv"></body>
</html>
这样一个简单的例子都不通过啊!
加了个 eval 也不行!
<html>
<head>
<script type="text/javascript">
function change(sva)
{
var str = "2,4,8,16";
var str1 = str.replace(new RegExp("(,?)"+sva+"(,?)"),"$1");
alert(str + '\n' +str1);
}
</script>
</head>
<body><input type="button" onclick="change(2)"
value="button" /><br>
<input type="text" name="vvv"></body>
</html>