我構建了一個響應式表單,並使用CSS媒體查詢來根據屏幕寬度更新佈局。響應式jquery驗證問題
在桌面視圖和移動&平板電腦視圖之間,表單的設計更改爲:標籤元素位於桌面寬度的輸入字段頂部,但隨後在屏幕縮小爲移動時成爲默認輸入字段值寬度。
我運行下面的函數放在標籤文本輸入字段的值: HTML:
<div class="sectionHeader" id="updateDetails">My details <span class="sectionEdit">Edit</span></div>
<div class="sectionWrapper" id="myDetails">
<div class="formSection clearfix">
<fieldset>
<legend>Personal</legend>
<div class="ctrlHolder">
<div class="ctrlHolder">
<label class="hiddenLabel" for="givenName">Given name</label>
<input name="givenName" id="givenName" type="text" class="text long required"/>
</div>
<div class="ctrlHolder">
<label class="hiddenLabel" for="familyName">Family name</label>
<input name="familyName" id="familyName" type="text" class="text long required"/>
</div>
</div>
</fieldset>
</div>
</div>
<div class="formSectionFooter clearfix">
<input data-target="myInvestment" class="sectionNavigator button secondary" id="sectionDetailsNext" name="sectionDetailsNext" type="button" value="Continue"/>
</div>
$('#details .formSection fieldset .ctrlHolder label').each(function(){
//console.log($(this).text());
$(this).addClass('hiddenLabel');
$(this).next('input').val($(this).text());
});
}
這與我的客戶端驗證嚴重破壞的領域正在測試空虛,他們變得完整和錯誤的默認值。除其他事項外空字段或默認值(如「選擇」,「名」,等等)驗證檢查
$('.sectionNavigator').click(function(event){
//$(this).closest('.formSection').validate();
validateMy.form();
event.preventDefault();
// check for any empty fields in the preceding section
var $thisFormSection = $(this).closest('.formSection');
var $elementsWithErros = $thisFormSection.find('input[value=""]:visible, input[class="error"]:visible, select[value="Day"]:visible, select[value="Month"]:visible, select[value="Year"]:visible, select[value="Select"]:visible, select[value="Please select"]:visible, select[value="Given name"]:visible, select[value="Family name"]:visible');
var target = $(this).attr('data-target');
有沒有人對如何處理這有什麼建議?
首先,請顯示錶格的HTML。其次,請構建一個jsFiddle演示。 – Sparky 2013-02-19 21:28:30
我一直在試圖寫一個小提琴,但不能真正把它的工作 - 我認爲這可能太複雜,這就是爲什麼我無法弄清楚它的方式。上面添加的HTML。感謝您的輸入。 – timmackay 2013-02-19 22:33:43
不需要jsFiddle,因爲這裏的問題不是關於JS中的錯誤,而是關於解決問題的方法。這就是爲什麼喬希能夠在沒有工作演示的情況下提出解決方案的原因。 – gpr 2013-02-19 22:51:37