.prop() returns object rather than value
<p>I'll try to make my question as simple and clear as possible. So i recently read the <a href="http://ift.tt/1lHNK0R"><code>.prop()</code> vs <code>.attr()</code></a> page on the stackoverflow, and decided i'd start using <code>prop()</code> instead of <code>attr()</code>.</p><p>HTML</p><pre><br /><code><form action="php/select.php" method="POST" class="ajax"><br /> <fieldset><br /> <legend>Show</legend><br /> <div><br /> <input type="submit" value="Show Servers"/><br /> </div><br /> <div id="output"></div><br /> </fieldset><br /> <input type="hidden" name="action" value="SHOW_SERVERS"/><br /></form><br /></code><br /></pre><p>JQuery</p><pre><br /><code>$(document).ready(function(){<br /> $("form.ajax").on("submit",function(e){<br /> e.preventDefault();<br /> var t=$(this);<br /> var form=t.serialize();<br /> var method=t.prop("method");<br /> var url=t.prop("action");//Before: t.attr("action");<br /> console.log(url);<br /> });<br />});<br /></code><br /></pre><p>Here comes the weird part, when i submit that form, what it prints in the console is this</p><p><a href="http://ift.tt/1Vpgr4k" rel="nofollow"><img src="http://ift.tt/1Vpgr4k" alt="enter image description here" /></a></p><p>My question is then:</p><p><strong>Why does JQuery return an input element rather than the value of the form action property?</strong></p><p><strong>Why can <code>.prop()</code> get the value of the method attribute, but not the action attribute</strong></p><p>PS: I already know the input has the property <code>name="action"</code>.</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34526069/prop-returns-object-rather-than-value">http://ift.tt/1Jfjevm</a></h2>
Nhận xét
Đăng nhận xét