定义<input name="objName" id="objID" value="" onFoucs="setParamater();">
<script>
setParamater=function(){
...
...
...}
</script>如何通过setParamater()方法来改变input组件中的ID属性值

解决方案 »

  1.   

    <input name="objName" id="objID" value="" onfocus="setParamater();"/>
    <span id="span"/>
    <script>
    var setParamater=function(){
    this.id="objID2";
    document.getElementById('span').innerText=this.id;
    }
    </script> 
      

  2.   

    不是改变ID值吗?SPAN只是显示出来看有没有改掉而已
    <input name="objName" id="objID" value="" onfocus="setParamater();"/>
    <span id="span"/>
    <script>
    setParamater=function(){
    this.id="objID2";
    document.getElementById('span').innerText=this.id;
    }
    </script> 
      

  3.   

    <script>
    setParamater=function(){this.id="abcd";
    alert(document.getElementById("abcd"));
    }
    </script>
    你可以试下这段代码,就知道能不能修改了
      

  4.   

    document.getElementById("").id = "";这样就可以改了,测试代码<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD><BODY>
    <input name="objName" id="objID" value="" /> 
    <span id="span"/> 
    <script> 
    alert(document.getElementById("objId").id) 
    document.getElementById("objId").id = "asdfa";
    alert(document.getElementById("asdfa").id) 
    </script> 
    </BODY>
    </HTML>
      

  5.   

    <input name="objName" id="objID" value="" onKeyUp="setParamater(this,this.value);"/>
    <input type="button" onclick="document.getElementById('span').innerText=(this.previousSibling.nodeType==3)?this.previousSibling.previousSibling.id:this.previousSibling.id" value="button"/>
    <span id="span" />
    <script>
    var setParamater=function(obj,newid){
    obj.id=newid;
    }
    </script> 不知道LZ的意思到底是什么,我改了一下,LZ测一下看看是不是这样
      

  6.   


    晕,LZ,你的方法名错了,所以有问题,看红色
    <input name="objName" id="objID" value="" onfocus="setParamater(this,'objID2');"/>
    <input type="button" onclick="alert(document.getElementById('objID2').value);" value="button"/>
    <span id="span" />
    <script>
    var setParamater=function(obj,newid){
    obj.id=newid;
    }
    </script> 
      

  7.   


    <input name="objName" id="objID" value="" onFoucs="setParamater();"> 
    <script> 
    setParamater=function(){ 
        var ctrlObjName = document.getElementByName('objName');
        if(ctrlObjName.length>0)
        {
            ctrlObjName.[0].id = "objID2";
        }

    </script>