且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

URL中的ASP.NET Web表单参数

更新时间:2023-11-26 13:05:52

经过更多研究之后,我认为这个javascript解决方案是***的:

After more research abut this topic I think that the javascript solution is the best:

您可以使用JavaScript访问表单的ACTION属性.

You can access the ACTION attribute of the form using JavaScript.

<form id="myForm" action="Search.aspx" onsubmit="return setAction();">
    <input id="textbox" />
    <input type="submit" value="Submit" />
</form>

<script type="text/javascript">

function setAction()
{
    var myForm = document.getElementById( "myForm" );
    var myText = document.getElementById( "textbox" );

    if (myForm && myForm.action && myText && myText.value != null )
    {
       myForm.action = "Search.aspx?q=" + myText.value;
    }
    return true;
}

</script>

我个人并不是JavaScript的忠实拥护者...但这不会向服务器添加额外的请求.如果您认为这样做有任何弊端,请告诉我.

Personally I am not a big fan of JavaScript ... but this does not add an extra request to the server. If you think that this has any drawbacks please let me know.