jquery,改变表单动作 [英] jquery, changing form action
问题描述
但操作仅针对删除表单(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):
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屋!