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)" >查看&nbsp;&nbsp;
            <input type="checkbox" id="dmethod" name="dmethod" value="2" onclick="doCheck(this)" >新增&nbsp;&nbsp;
            <input type="checkbox" id="dmethod" name="dmethod" value="4" onclick="doCheck(this)" >修改&nbsp;&nbsp;
            <input type="checkbox" id="dmethod" name="dmethod" value="8" onclick="doCheck(this)" >删除&nbsp;&nbsp;
            <input type="checkbox" id="dmethod" name="dmethod" value="16" onclick="doCheck(this)" >批量删除          
  
          </td>
        </tr>
dmvalue.replace(/(,?)objvalue(,?)/,"$1");的值并没有改变。

解决方案 »

  1.   

    将值打出来看看先
    alert(dmvalue);
    dmvalue = dmvalue.replace(/(,?)objvalue(,?)/,"$1");
    alert(dmvalue);
      

  2.   

    /(,?)objvalue(,?)/
    是判断值得是不是等于",objvalue,"的...
    不是你想要的把值赋给中间的objvalue的效果...用var re=RegExp("(,?)"+objvalue+"(,?)")
    试试
      

  3.   

    就算改变了你也没赋值
    dmvalue.replace(/(,?)objvalue(,?)/,"$1");改成dmvalue = dmvalue.replace(/(,?)objvalue(,?)/,"$1");
      

  4.   

    dmvalue = dmvalue.replace((new RegExp("(,?)"+objvalue+"(,?)")),"$1"); 
      

  5.   

    <html>
    <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>
    这样一个简单的例子都不通过啊!
      

  6.   


    加了个  eval  也不行!
      

  7.   

    replace已执行了,但执行结果你没有赋给任何一个变量,稍改了一下试试:
    <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>