標籤

ASP.NET MVC (29) Visual C# (15) JQuery (10) Plugins (8) JQuery Plugins (6) JavaScript (6) MySQL (5) CSS (4) LinQ (4) Mac OS (4) CentOS (3) Design Pattern (3) Entity Framework (3) IIS (3) Python (3) Windows (3) php (3) Docker (2) LAMP (2) SQL Server (2) WCF (2) .NET (1) .NET Core (1) AWS (1) Browser (1) GIS (1) IE (1) Internet Security (1) Linux (1) Platform (1) React (1) SEO (1) Testing (1) VMware (1) Windows 7 (1) cookie (1) curl (1) laravel (1) phpBB (1) session (1) 中古屋 (1) 透天 (1) 閒言閒語 (1) 面試 (1) 鳥松 (1)

2011年3月31日 星期四

[JQuery] 在表單中(Form),如何取得多個input欄位的value值?

How to get the value of multiple input fields in the form post
==================
HTML:

<form action="/EditWebSiteLinksPOrderAjax" id="postForm">
<ul id="sortableUL">
<li id="sort_0" class="ui-state-default">

<input id="order0" name="POrder" type="hidden" value="0" />
<input id="WebSiteLinksId" name="WebSiteLinksId" type="hidden" value="2" />
</li>
<li id="sort_1" class="ui-state-default">
<input id="order1" name="POrder" type="hidden" value="1" />
<input id="WebSiteLinksId" name="WebSiteLinksId" type="hidden" value="3" />
</li>
<li id="sort_2" class="ui-state-default">
<input id="order2" name="POrder" type="hidden" value="2" />
<input id="WebSiteLinksId" name="WebSiteLinksId" type="hidden" value="5" />
</li>
<li id="sort_3" class="ui-state-default">
<input id="order3" name="POrder" type="hidden" value="3" />
<input id="WebSiteLinksId" name="WebSiteLinksId" type="hidden" value="6" />
</li>
</ul>
<p>
<input type="submit" value="確定" />
</p>
</form>



【JQuery】:
var $form = $("#postForm");

(1) $form.find('input[name="POrder"]').map(function () { return $(this).attr("value") })
["0", "1", "2", "3"]


(2) $form.find('input[name="POrder"]').serializeArray()
=[Object { name="POrder", value="0"}, Object { name="POrder", value="1"}, Object { name="POrder", value="2"}, Object { name="POrder", value="3"}]

沒有留言:

張貼留言