我有一個表單,它使用可視爲頁面的字段集。獲取一個元素中的所有data- *屬性,並將它們放入一個數組中
1字段集= 1頁
這些字段集在端部將是動態的,從數據庫etcetc。 我需要找到一種方法來從字段集中的輸入中獲取所有data- *屬性。有關驗證規則。因爲這些也是動態的。取決於客戶的需求。
<form id="msform">
<!-- progressbar -->
<!-- fieldsets foreach every group -->
<fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<!-- foreach every input that belongs to the group -->
<input type="text" name="email" placeholder="Email" data-email="true" data-required="true" />
<input type="password" name="pass" placeholder="Password" id="pass" data-required="true" />
<input type="password" name="cpass" placeholder="Confirm Password" data-required="true" data-equalto="#pass" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Social Profiles</h2>
<h3 class="fs-subtitle">Your presence on the social network</h3>
<input type="text" name="twitter" placeholder="Twitter" />
<input type="text" name="facebook" placeholder="Facebook" />
<input type="text" name="gplus" placeholder="Google Plus" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Personal Details</h2>
<h3 class="fs-subtitle">We will never sell it</h3>
<input type="text" name="fname" placeholder="First Name" />
<input type="text" name="lname" placeholder="Last Name" />
<input type="text" name="phone" placeholder="Phone" />
<textarea name="address" placeholder="Address"></textarea>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title">Terms Of Service</h2>
<h3 class="fs-subtitle">We will never sell it</h3>
<input type="text" name="fname" placeholder="First Name" />
<input type="text" name="lname" placeholder="Last Name" />
<input type="text" name="phone" placeholder="Phone" />
<textarea name="address" placeholder="Address"></textarea>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="submit action-button" value="Submit" />
</fieldset>
</form>
如何遍歷所有輸入? 關鍵是驗證用戶何時單擊下一頁(用於下一頁),但仍將所有內容保存在一個表單中。
任何人有想法?
如果你使用庫很好,我會說,使用[JQuery驗證插件](http:// jqueryvalidation。org /) – 2014-10-10 07:01:34
我認爲你只是在尋找'data- *'屬性 – 2014-10-10 07:01:35
@LearningNeverStops試過了,那個插件會一次性驗證整個表單,而我只有在那個時候才需要驗證頁面。 – user3446397 2014-10-10 07:09:35