下拦菜单有值8:30
            9:00
            9:30
文本框原来有值为:2006-11-15
当选择8:30时,则文本框显示:2006-11-15 8:30
当选择9:30时,则文本框显示:2006-11-15 9:30
请问如何实现?如果文本框原来的值为:2006-11-15 9;30:00
当选择8:30时,则文本框也能显示:2006-11-15 8:30

解决方案 »

  1.   

    比较笨的方法:
    <script type="text/javascript">
    function check()
    {
    var i=document.getElementsByTagName("option");
    document.getElementById("txt1").value="2006-11-25  ";
    for(var j=1;j<i.length;j++)
    {
    if(i[j].selected==true)
    {
    document.getElementById("txt1").value+=i[j].text;
    }
    }
    }
    </script>
    <select name="ces" onChange="check()">
      <option selected>please select a time</option>
      <option>8:30</option>
      <option>9:30</option>
    </select>
    <input name="test" id="txt1" value="2006-11-25  ">
      

  2.   

    <meta name="Description" content="">
    <script language="JavaScript" src="jquery1.1.2.js"></script>
    </head><body>
    <form method=post action="">
    <input type="text" id="t1" value="2006-11-15">
    <select id="s1" onchange="test();">
    <option value='8:30'>8:30</option>
    <option value='9:00'>9:00</option>
    <option>abc</option>
    <option>dddd</option>
    </select>
    </form><script language="JavaScript">
    <!--
    var val = $('#t1').val();
    function test()
    {
    //alert(document.all['s1'].options[0].innerText);
    var obj = $('#s1').children().eq(document.all.s1.selectedIndex).text()
    if ($('#t1').val().length != 0)
    {
     $('#t1').val(val+obj);
    }
    //alert($('#t1').val().length);
    }
    //-->
    </script>
    </body>
      

  3.   

    <form name="form_name">
    <select name="stime" onchange="doit();">
    <option value="8:30">8:30</option>
    <option value="9:00">9:00</option>
    <option value="9:30">9:30</option>
    </select>
    <input type="text" name="sday" value="2006-11-15 9;30:00">
    </form>
    <script>
    function doit(){
    var stime = document.form_name.stime.options[document.form_name.stime.selectedIndex].value;
    var sday  = document.form_name.sday.value;
    var arr = sday.split(" ");
    if(arr.length) document.form_name.sday.value = arr[0] + " " + stime;
    }
    </script>