admin管理员组文章数量:1391964
Here is a simple form:
<form action="hello">
</form>
If I use
var action = $('form').attr('action');
I get the correct value, "hello". But if I use
var action = $('form').prop('action');
I get
http://localhost/hello
What's up with that?
I read that I should use prop() instead of of attr() but here it returns incorrect value
Here is a simple form:
<form action="hello">
</form>
If I use
var action = $('form').attr('action');
I get the correct value, "hello". But if I use
var action = $('form').prop('action');
I get
http://localhost/hello
What's up with that?
I read that I should use prop() instead of of attr() but here it returns incorrect value
Share Improve this question asked Dec 11, 2014 at 7:26 Anna K.Anna K. 2,0056 gold badges28 silver badges40 bronze badges 3-
how about
var action = document.form.action
? – Igor Savinkin Commented Dec 11, 2014 at 7:31 -
@IgorSavinkin
document.forms[0].action
then. And it will return absolute path. – Regent Commented Dec 11, 2014 at 7:33 -
Who told you to use
prop
and why? – David Knipe Commented Dec 11, 2014 at 8:20
1 Answer
Reset to default 10When you say prop
, it will get the absolute path of the target resource but .attr()
will read the attribute value as it is.
Since you have used relative path in the action, prop
will use the path of the current page to construct the actual url to which the form will be submitted.
本文标签: javascriptForm action value difference in prop and attrStack Overflow
版权声明:本文标题:javascript - Form action value difference in prop and attr - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744743709a2622763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论