如何使用ASP.NET更改表单元素的操作部分

本文关键字:元素 操作部 表单 何使用 ASP NET | 更新日期: 2023-09-27 18:02:23

使用ASP创建的页面上的form元素。. NET看起来是这样的(如果我从web浏览器"查看页面源"):

< form method="post" 
       action="Page.aspx?lang=en-US&amp;pp=10&amp;bi=10" 
       id="ctl01" enctype="multipart/form-data">

如何访问表单元素?我需要从action元件中去除&amp;pp=10&amp;bi=10部分?

如何使用ASP.NET更改表单元素的操作部分

如果你的页面上只有一个表单,那么尝试在你的javascript

alert(document.forms[0].action);

要改变动作,就像这样做

var actionPath = document.forms[0].action;
// your logic to remove unwanted string with the help of string functions in JS
document.forms[0].action = actionPath;

如果你知道你的表单的名字,那么像这样访问它

document.forms['YOUR_FORM_NAME'].action

,或者您也可以使用客户端id访问它,如果您想要考虑您的表单设置runat="server with it

document.getElementById(....)// Client Id of the form control