<html>
<head><script language="javascript">function showValue(){
var str= window.showModalDialog("#","");
document.myFrom.textfield.value=str; }
</script>
</head><body>
<p ><a href="#">大海战2</a>&nbsp;</p>
<p ><a href="#">仙剑奇侠传</a>&nbsp;</p>
<p ><a href="#">联合进攻</a>&nbsp;</p>
<form action="" method="get" name="myFrom" id="myFrom">
  你的选择是
  <label for="textfield"></label>
  <input type="text" name="textfield" id="textfield"  class="border" />
  <label for="Submit">
  <input type="button" name="Submit" value="确认" id="Submit"   class="Submit"  />
  </label>
</form>
</body></html>
当单击超链接,怎么样把超链接的字符串,转给文本框txtfield.比如:单击连接:联合进攻。则文本框的值就是:联合进攻
各位大侠教教哦

解决方案 »

  1.   


    <html> 
    <head> <script language="javascript"> function showValue(){ 
    var str= window.showModalDialog("#",""); 
    document.myFrom.textfield.value=str; } function fillValue(o){
    document.getElementById('textfield').value = o.innerHTML
    }
    </script> 
    </head> <body> 
    <p > <a href="#" onclick="fillValue(this);">大海战2 </a>&nbsp; </p> 
    <p > <a href="#" onclick="fillValue(this);">仙剑奇侠传 </a>&nbsp; </p> 
    <p > <a href="#" onclick="fillValue(this);">联合进攻 </a>&nbsp; </p> 
    <form action="" method="get" name="myFrom" id="myFrom"> 
      你的选择是 
      <label for="textfield"> </label> 
      <input type="text" name="textfield" id="textfield"  class="border" /> 
      <label for="Submit"> 
      <input type="button" name="Submit" value="确认" id="Submit"  class="Submit"  /> 
      </label> 
    </form> 
    </body> </html> 
      

  2.   


    window.onload = function() {
    var arr = document.getElementsByTagName("a");
    for (var i=0;i<arr.length ; i++){
    arr[i].onclick = (function(i){ return function(){
    document.getElementById("textfield").value = arr[i].innerText;
    }
    })(i)
    }
    }