一个页面有8个按钮,一个文本框,点击按钮1,文本框的值为1,点击按钮2,文本框的值为2....如何实现?小弟菜鸟,谢谢帮忙!

解决方案 »

  1.   

    <script type="text/javascript">
    <!--
    function setVal(obtn){
    document.getElementById("txt").value = obtn.value.slice(2);
    }
    //-->
    </script>
    <input type="text" id="txt" /><br/>
    <input type="button" value="按钮1" onclick="setVal(this)" />
    <input type="button" value="按钮2" onclick="setVal(this)" />
    <input type="button" value="按钮3" onclick="setVal(this)" />
      

  2.   

    <script type="text/javascript">
    function doit(n){
    document.forms[0].txt.value=n;
    }window.onload = function(){
      //setInterval("doit()", 5000);
    }
    </script>
    <form>
    <input type="text" name="txt">
    <input type="button" value="1" onclick="doit(1)">
    <input type="button" value="2" onclick="doit(2)">
    <input type="button" value="3" onclick="doit(3)">
    <input type="button" value="4" onclick="doit(4)">
    <input type="button" value="5" onclick="doit(5)">
    <input type="button" value="6" onclick="doit(6)">
    <input type="button" value="7" onclick="doit(7)">
    <input type="button" value="8" onclick="doit(8)"></form>
      

  3.   

    <script language="javascript" type="text/javascript"> 
    function CheckTest(id)
            {
                
                window.textId1.value=id;
            }
    </script><input type="text" name="text1" id="textId1" />
        <input type="button" name="btn1" id="btnId1" value="按钮1" onclick="CheckTest(1)" />&nbsp
        <input type="button" name="btn2" id="btnId2" value="按钮2" onclick="CheckTest(2)" />&nbsp
        <input type="button" name="btn3" id="btnId3" value="按钮3" onclick="CheckTest(3)" />&nbsp
        <input type="button" name="btn4" id="btnId4" value="按钮4" onclick="CheckTest(4)" />&nbsp
        <input type="button" name="btn5" id="btnId5" value="按钮5" onclick="CheckTest(5)" />&nbsp
        <input type="button" name="btn6" id="btnId6" value="按钮6" onclick="CheckTest(6)" />&nbsp
        <input type="button" name="btn7" id="btnId7" value="按钮7" onclick="CheckTest(7)" />&nbsp
        <input type="button" name="btn8" id="btnId8" value="按钮8" onclick="CheckTest(8)" />&nbsp
      

  4.   

    <input type="text" id="Text1"/>
    <input type="button" id="Button1" onclick="Show(1)" />
    ......
    function Show(id)
    {
       document.getElementById("Text1").value=id;
    }