jquery,改变表单动作 [英] jquery, changing form action

查看:122
本文介绍了jquery,改变表单动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到答案。我上传的代码到pastebin(所以不会混乱了帖子):



http://pastebin.com/BhnNTnJM



但操作仅针对删除表单(id = form-horse-delete)进行更改,而不是其他两种形式位于页面上。我在我的智慧结束试图找出为什么它不适用于2形式,但将为1形式。



在IE中,如果我尝试并改变2个窗体的动作,它会给出一个javascript错误。但是如果我把这个改变拿出来,它就可以正常工作,不会出现javascript错误。 你有一个名为的输入字段,在form-horse-update和form-horse-add表单中执行 操作。例如

 < input type =hiddenname =actionvalue =add/> 

动作是一种保留字,因为具有输入字段该名称会改变表单的行为。通常在JavaScript中(更不用说jQuery)引用类似于:

  document.myform.action 

引用表单的action属性。在添加一个名为action的输入字段的那一刻,相反,上述内容将引用输入元素action,并且不再有访问表单的action属性的方法。



最好的解决方案是将您的 action 输入字段重命名为其他内容(但最好不要将其重命名为 submit !;))


i cannot seem to find the answer to this. i uploaded code to pastebin (so wouldnt clutter up the post):

http://pastebin.com/BhnNTnJM

but the action only changes for the delete form (id=form-horse-delete) and not the other 2 forms located on the page. i am at my wits end trying to figure out why it doesn't work for the 2 forms, yet will work for the 1 form.

in IE, if i try and change the action of the 2 forms, it gives a javascript error. but if i take out the change, it works fine with no javascript error.

解决方案

You have an input field called action in the form-horse-update and form-horse-add forms. e.g.

<input type="hidden" name="action" value="add" />

action is kind of a reserved word, as having an input field with that name changes the behaviour of the form. Normally in JavaScript (let alone jQuery) a reference to something like:

document.myform.action

refers to the action attribute of the form. The minute you add an input field called action then instead the above would refer to the input element called action and there is no longer a way to access the form's action attribute.

The best solution is to rename your action input fields to something else (but probably best not to rename it to submit! ;) )

这篇关于jquery,改变表单动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆