function convertStringText(str1,str2,divId,inputId){
var s1=str1;
var str=/{*\{*\}*}/;

    if(str.exec(s1)){
     s1=s1.replace(/\{([^\}]+)\}/g,'<input type="text" class="'+inputId+'" style="border-color: #878787; border-style: solid; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px;text-align:center" size="10" maxlength="10" id="'+inputId+'" value="" />');
    }
var msg='<input type="checkbox" onclick="document.getElementById('+inputId+').name('+inputId+')"  id="'+inputId+'" value="'+str2+'""/>';
if(s1==""){
     $("#"+divId).html($("#"+divId).html()+msg+str1+'<br/>');
}else{
$("#"+divId).html($("#"+divId).html()+msg+s1+'<br/>');

}想在点击复选框的时候给 input设置name  想在后面 用name取值
onclick 事件 报错  这样不行的话 有什么别的方法 应该怎么做

解决方案 »

  1.   

    可以这样吗?
     onclick='fnSetName(this)'然后fnSetName方法里获取this对象后设定attributes  
      

  2.   


    function convertStringText(str1,str2,divId,inputId){
    var s1=str1;
    var str=/{*\{*\}*}/;

        if(str.exec(s1)){
         s1=s1.replace(/\{([^\}]+)\}/g,'<input type="text" class="'+inputId+'" style="border-color: #878787; border-style: solid; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px;text-align:center" size="10" maxlength="10" id="'+inputId+'" value="" />');
        }
    var msg= '<input type="checkbox" onclick="fnSetName(this)"  id="'+inputId+'" value="'+str2+'""/>';
    if(s1==""){
         $("#"+divId).html($("#"+divId).html()+msg+str1+'<br/>');
    }
    else{
    $("#"+divId).html($("#"+divId).html()+msg+s1+'<br/>');

    }
    function fnSetName(){
    $(this).attr('name','');
    }
    function getByTagName() {
    $('input[name="设定的Name值"]');
    }
    根据我的理解给你写个大概的意思
      

  3.   

    function getByTagName() {
                $('input[name="设定的Name值"]');
            } 
    这个方法 在哪用到啊
      

  4.   

    为什么 我只能 改 第一个input的 name呢  
    function fnSetName(inputId,name){
    alert(name);
        $("#"+inputId).attr('name',name);
        $("#"+inputId).attr('disabled','');
    }
    function convertStringText(str1,str2,divId,inputId){
    var s1=str1;
    var str=/{*\{*\}*}/;

        if(str.exec(s1)){
         s1=s1.replace(/\{([^\}]+)\}/g,'<input type="text" disabled="disabled" class="'+inputId+'" style="border-color: #878787; border-style: solid; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px;text-align:center" size="10" maxlength="10" id="'+str2+'" value="" />');
        }
    var msg='<input type="checkbox" onclick="fnSetName(this.value,this.name)" name="'+inputId+'" id="'+inputId+'checkbox" value="'+str2+'"/>';
        if(s1==""){
         $("#"+divId).html($("#"+divId).html()+msg+str1+'<br/>');
    }else{
    $("#"+divId).html($("#"+divId).html()+msg+s1+'<br/>');

    }
      

  5.   

    你在控制台中输出$("#"+inputId)  看看这个对象是什么样子的。  
      

  6.   


    这个你不是说要根据name获取到对象嘛。这个就是啊。然后 进行取值啊或者其他操作
      

  7.   

    value 是
    function(a){if(a===w){var b=this[0];if(b){if(c.nodeName(b,"option"))return(b.attributes.value||{}).specified?b.value:b.text;if(c.nodeName(b,"select")){var d=b.selectedIndex,f=[],e=b.options;b=b.type==="select-one";if(d<0)return null;var j=b?d:0;for(d=b?d+1:e.length;j=0;else if(c.nodeName(this,"select")){var u=c.makeArray(r);c("option",this).each(function(){this.selected= c.inArray(c(this).val(),u)>=0});if(!u.length)this.selectedIndex=-1}else this.value=r}})}
    $("#"+inputId)  是 object object
      

  8.   

    直接用attr获得name进行赋值吧
      

  9.   


    说明是2个对象你要一个个去修改$($("#"+inputId)[i]).attr才行
      

  10.   


    function fnSetName(inputId,name){
        $("#"+inputId).attr('name',name);
        $("#"+inputId).attr('disabled','');
        for(var i=0;i<10;i++){
         $($("#"+inputId)[i]).attr('disabled','');
         $($("#"+inputId)[i]).attr('name',name);
        }
    }
    还是只能 改一个呀 
      

  11.   


     你点击一个checkbox就要把所有checkbox都设置name吗? 还有id最好不要重覆。这样设计是有问题的。
    如果你点击checkbox就要全部设置全部checkbox
    可以这样
    var checkboxArray = $('#'+所有checkbox的父层节点id +' checkbox')  这个是数组对象
    然后再遍历设置还有你这个 for(var i=0;i<10;i++){
         $($("#"+inputId)[i]).attr('disabled','');
         $($("#"+inputId)[i]).attr('name',name);
        }写法肯定是错的啊 你怎么能写死成10呢?要用$("#"+inputId)[i].length 借助于chrome  多调调啊 
      

  12.   

    我这个 是 在点击 checkbox  的时候 启用这些 input  然后取这些值
      

  13.   


    点击checkbox 获取其他的input? 这样吧 你把你的需求抽出来(注意要完整并且无关内容要少)。我给你做个demo