简体   繁体   English

在prop和attr中形成动作值差异

[英]Form action value difference in prop and attr

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 我读到我应该使用prop()而不是attr(),但在这里它返回不正确的值

When you say prop , it will get the absolute path of the target resource but .attr() will read the attribute value as it is. 当你说prop ,它将获得目标资源的绝对路径,但.attr()将按原样读取属性值。

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. 由于您在操作中使用了相对路径,因此prop将使用当前页面的路径来构造将提交表单的实际URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM