<input type="radio" name="fruit" value=""><input type="text" name="others">我想要后面这个文本框提交的值传入到前面的radio值中,而文本框则是由点击radio时出现。

解决方案 »

  1.   

    <script Language="JavaScript">
      function reload(s){
        document.all.fruit.value=s;
      }
      function reloads(){
       alert(document.all.fruit.value);
      }
    </script> <input type="radio" name="fruit" value="Pear"  onclick="reload(this.value);">Pear<br>
     <input type="radio" name="fruit" value="orange" onclick="reload(this.value);">orange<br>
     <input type="radio" name="fruit" >
     <input type="text" onkeyUp="reload(this.value);"name="others"><br/>
     <input type="submit" value="submit" onclick="reloads();">
      

  2.   

    <body>
    <form id="form1" name="form1" method="post" action="">
      <input type="radio" name="radiobutton" value="red" />红色
      <input name="radiobutton" type="radio" value="green" checked="checked" />
      绿色
      <input type="radio" name="radiobutton" value="black" />黑色
      <input name="radiobutton" type="radio" onfocus="document.all['text'].style.display='block';" value="other" />其它
    <input name="text" type="text" onblur="add_radio(this.value)" style="display:none;"/>
    <input type="button" onclick="alert(document.getElementsByTagName('input')[3].value);" value="查看值"/>
    </form>
    </body>
    <script language="javascript">
    function add_radio()
    {
    var obj;
    obj=document.getElementsByTagName("input");
    obj[3].value=document.all['text'].value;
    }
    </script>
      

  3.   


    <script Language="JavaScript">  function reload(s){
    document.getElementById("file1").style.display="none";
        document.all.fruit.value=s;
      }
      //隐藏层
      function rel(){
            document.getElementById("file1").style.display="block";
      }
    function reloads(){
       alert(document.all.fruit.value);
      }
    </script> <input type="radio" name="fruit" value="Pear"  onclick="reload(this.value);">Pear<br>
     <input type="radio" name="fruit" value="orange" onclick="reload(this.value);">orange<br>
     <input type="radio" name="fruit" onclick="rel();"><div id="file1" style="display:none;"><input type="text" onkeyUp="reload(this.value);" name="others"></div> 
     <br/>
    <input type="submit" value="submit" onclick="reloads();">
      

  4.   


    <!-----随便写的,供LZ参考--------------------->
    <input type="radio" name="fruit" value="Apple">
                                  Apple<br>
    <input type="radio" name="fruit" value="Pear">
                                  Pear<br>
    <input type="radio" name="fruit" value="orange">
                                 orange<br>
    <input id="othersRad" type="radio" name="fruit" value="" onclick="check()"><span id="othersSpan">自定义</span><input id="othersTxt" type="text" name="others" style="display:none;" onkeypress="Txt_onkeypress()"><br>
    <input type="submit" value="submit"><script>
    function check()
    {
    if (document.getElementById("othersRad").checked==true)
    {document.getElementById("othersTxt").style.display="";}
    }//回车
    function Txt_onkeypress()
    {
    if (event.keyCode==13)
    {
    document.getElementById("othersSpan").innerText=document.getElementById("othersTxt").value;
    document.getElementById("othersTxt").style.display="none";
    }
    }
    </script>
      

  5.   

    loveyunwent的可以达到目的,但有个严重的问题就是
    点击后出现了文本框,但输入文字时候,随便打入一个字母,文本框就会再次隐藏,需要继续点击才可以再出现。也就是说不可以正常的输入完整的文字。为什么呢?
      

  6.   

    <div id="file1" style="display:none;"><input type="text" onkeyUp="reload
    (this.value);" name="others"></div> 
    换成
    <div id="file1" style="display:none;"><input type="text" onblur="reload
    (this.value);" name="others"></div> 旧好了啊
    监空的事件不一样
      

  7.   

    cnchart:
    请问你的代码里面的[3]是什么意思?
      

  8.   

    Gt7466的代码提交后会多出一个on的字样
      

  9.   


    这个是改了以后的代码<script Language="JavaScript">  function reload(s,q){
       if(q=="w"){
        document.getElementById("file").style.display="none";
      }
        document.getElementById("file1").style.display="none";
        document.all.fruit.value=s;
        document.getElementById("dd").innerHTML=s;
      }
      //隐藏层
      function rel(){
            document.getElementById("dd").innerHTML="";
            document.getElementById("file").style.display="block";
            document.getElementById("file1").style.display="block";
      }
    function reloads(){
       alert(document.all.fruit.value);
      }
    </script>
     <input type="radio" name="fruit" value="Pear"  onclick="reload(this.value,'w');">Pear<br>
     <input type="radio" name="fruit" value="orange" onclick="reload(this.value,'w');">orange<br>
     <input type="radio" name="fruit" onclick="rel();"><div id="file" style="display:none;"><span id="dd"></span></div><div id="file1" style="display:none;">
     <input type="text" onblur="reload(this.value,'q');" name="others"></div> 
     <br/>
    <input type="submit" value="submit" onclick="reloads();">
      

  10.   


    是指radio"其它",如为2,就是指radio"黑色"看看document.getElementsByTagName的说明吧
      

  11.   


    <html>
    <head>
    <script type="text/javascript">
    function dosome()
    {
    var newRadioTxt = document.all.others.value;
    if ( newRadioTxt == "" )
    {
    return;
    }
    var fruit = document.all.fruit;
    var radio = document.createElement("<input name='"+ "fruit" +"'/>");
    //var radio = document.createElement("input");
    radio.setAttribute("type","radio");
    //radio.setAttribute("name","fruit");
    radio.setAttribute("value",newRadioTxt);
    var txt = document.createTextNode(" "+radio.value);
    var br = document.createElement("br");
    document.all.main.appendChild( radio );
    document.all.main.appendChild( txt );
    document.all.main.appendChild( br );
    document.getElementById("others").value = "";
    }
    </script>
    </head>
    <body>
    <div id="main" onclick="document.getElementById('others').style.display='';">
     <input type="radio" name="fruit" value="Apple">
                                  Apple<br>
                                  <input type="radio" name="fruit" value="Pear">
                                  Pear<br>
                                  <input type="radio" name="fruit" value="orange">
                                 orange<br>
    </div>
    <input type="text" name="others" style="display:none" onblur="this.style.display='none';">
    <br>
    <input type="submit" onclick="dosome();">
    </body>
    </html>
      

  12.   


    <body>
    <form id="form1" name="form1" method="post" action="">
      <input type="radio" name="color" value="red" onclick="disp();"/>红色
      <input name="color" type="radio" value="green" onclick="disp();"/>
      绿色
      <input type="radio" name="color" value="black" onclick="disp();"/>黑色
      <input id="other" type="radio" name="color" onclick="document.getElementById('ottxt').style.display='inline'" value="other" />其它
    <input id="ottxt" name="ipt" type="text" onblur="add_radio(this.value)" style="display:none;"/>
    <input type="button" onclick="alert(document.getElementById('other').value);" value="查看值"/>
    <input type="submit" onclick="ka()" value="查看最后值" />
    </form>
    </body>
    <script language="javascript">
    function add_radio()
    {
    document.getElementById("other").value=document.getElementById("ottxt").value;
    }
    function disp()
    {
    if(document.form1.ipt.style.display=="")
    {document.form1.ipt.style.display="none"}
    }
    function ka()
    {
     for(i=0;i<document.all.color.length;i++)
    {if(document.all.color[i].checked)
     {var ftt;
     ftt=document.all.color[i].value;
     alert(ftt);}
    }
    }
    </script>