gpt4 book ai didi

javascript - 使用 ExtJs 拦截 HTML 表单和值

转载 作者:行者123 更新时间:2023-11-29 22:39:48 26 4
gpt4 key购买 nike

我试图拦截表单的提交,以便使用 ExtJS 在视口(viewport)中创建 Ajax 请求。有些表单没有名称(或没有 ID),在许多情况下,提交按钮已被一个简单的按钮更改。

案例一:

<form action="?m=pros&a=add" method="post">
<input type="hidden" name="project_type value='software'>
<input type="submit" class="button" value="Add Project"/>
</form>

案例二

<form action="?m=pros&a=edit" method="post">
<input type="button" class="button" value="Edit Project"
onclick="javascript:doTheSubmitting(this)
/>
</form>

我的 Javascript 代码中有:

    initEvents : function(){
contentPanel.superclass.initEvents.call(this);
this.body.on('click', this.myClick, this);
},

myClick: function(e, target){
/*handler for intercept click over link, submit, buttons*/

//first issue: how to identify: link, button, submit

targeIstLink = e.getTarget('a:not(.exi)', 3); //target is a Link
targetIsForm = target.form; //target is a form????

e.stopEvent();

/*solved*/
if(targetIsLink){
//code to ajaxify a link and
//load it in the viewport pannel
}else

/*not solved*/
if(targetIsForm){
//code to ajaxify a form and load it in the panel ViewPort
}else
if(targetIsFileUpload) { /*coding*/
//code here
}

},

最佳答案

算法:

switch( link )

1. link.parent is a Form Object? /*Parent of a submit button*/
1.1 if True,
newLink = serialize( Form Object ) /*No Break clause*/
2. newLink = formatLinkAsYouLike( link ) /*In the case of a link nodeTag='A' */
Default: /*both cases */
a) .load(newLink, Params)
b) handle whatever you want: onSubmit, onSuccess, onError, onEtcetera

end Switch

关于javascript - 使用 ExtJs 拦截 HTML 表单和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3580442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com