我如何通过文本框值在href

本文关键字:href 文本 何通过 | 更新日期: 2023-09-27 18:12:48

大家好,我的输入文本声明如下

<input name="text1" type="text" id="text1" value="textbox 1" onBlur="toggleVisibility(this.name);">

我想在我的href中传递text值。我试了下面的,但我无法得到的值,谁能帮助我

<a href="http://paymycheck.info/federalregulartaxcalculator.aspx?id="+document.getElementById('text1').value;target="_blank"  style="text-decoration:underline; text-align:right; color:#222; font-family:Arial; font-size:12px; font-weight:normal;"> Unsubscribe </a>

我如何通过文本框值在href

你可以这样尝试…使用javascript函数…

 <input type="text" id="myText"/>
<a href="javascript:RedirectToSecondPage()">click here</a>
<script type="text/javascript">
function RedirectToSecondPage()
{
   var input = document.getElementById('myText');
   var value = input ? input.value : 'defaultText';
   window.location.href = 'mySecond.asp?MyText=' + escape(value);
}
</script>

如果你真的想要实际的值,你可以这样做:

<input name="text1" type="text" id="text1" value="textbox 1" onBlur="toggleVisibility(this.name);">
<a href="javascript:document.location.href='http://paymycheck.info/federalregulartaxcalculator.aspx?id=' + document.getElementById('text1').value">Unsubscribe</a>
然而,这可能会产生不必要的副作用(例如,空格在URL中显示为实际的空格)。如果您可以更改输入的名称,您可以考虑通过适当的形式进行更改:
<form id="myform" action="http://aaapaymycheck.info/federalregulartaxcalculator.aspx" method="get">
    <input name="id" type="text" id="text1" value="textbox 1" onBlur="toggleVisibility(this.name);">
</form>
<a href="javascript:document.getElementById('myform').submit()">Unsubscribe</a>