我目前正在创建一个使用步骤的捐赠表格。为了一步一步地移动,我正在使用 jQuery(特别是以下函数):
function showNextStep(currentStep) {
$("#step" + currentStep).slideToggle("slow", function () {
if (currentStep === 1) {
//figure out what kind of donation they are making
var chosenDonationType = $("[name=donationType]").val();
//show the apppropriate slide
switch (chosenDonationType) {
case "oneTimeGift":
currentStep += 1;
$("#makingAOneTimeGift").show();
$("#step" + currentStep).slideToggle("slow");
break;
case "recurringDonation":
currentStep += 1;
$("#makingARecurringGift").show();
$("#step" + currentStep).slideToggle("slow");
break;
//if somehow they changed it to something else, ignore them and return false.
default:
return false;
//break; not needed due to return
}//end switch
} else {
currentStep += 1;
$("#step" + currentStep).slideToggle("slow");
}
});
}
我也有一份用户可以捐赠的资金清单。之后的步骤 (id="step4") 用于分配。如果用户只选择一个复选框,我想跳过该步骤并将相应的输入值设置为 100。抓住的是,我不知道如何遍历复选框数组(我假设使用 [name=list-item])并发现只选择了一个,确定哪个,然后跳过下一步下一步和将相应分配框的值设置为 100。执行此操作的性能有效方法是什么?
复选框使用以下样式:
<label class="checkbox">
<input type="checkbox" id="showGoodMenGoodCitizensAllocation" name="list-items[]" value="Good_Men_Good_Citizens" />
Good Men, Good Citizens Scholarship
</label>
<label class="checkbox">
<input type="checkbox" id="showClassof2012Allocation" name="list-items[]" value="Class_Of_2012" />
Class of 2012 Scholarship <abbr title="In Honor Of">IHO</abbr> Mr. Jason M. Ferguson ’96
</label>
<label class="checkbox">
<input type="checkbox" id="showClassof2011Allocation" name="list-items[]" value="Class_Of_2011" />
Class of 2011 Scholarship <abbr title="In Honor Of">IHO</abbr> Ms. Anita Garland
</label>
分配输入如下:
<div id="GoodMenGoodCitizensAllocation" class="input-append hiddenByDefault">
<input type="number" name="Good_Men_Good_Citizens-Allocation" min="0" max="100" value="0" />
<span class="add-on">% to the Good Men, Good Citizens Scholarship</span>
</div>
<div id="ClassOf2012Allocation" class="input-append hiddenByDefault">
<input type="number" name="Class_Of_2012-Allocation" min="0" max="100" value="0" />
<span class="add-on">% to the Class of 2012 Scholarship <abbr title="In Honor Of">IHO</abbr> Mr. Jason M. Ferguson ’96</span>
</div>
<div id="ClassOf2011Allocation" class="input-append hiddenByDefault">
<input type="number" name="Class_Of_2011-Allocation" min="0" max="100" value="0" />
<span class="add-on">% to the Class of 2011 Scholarship <abbr title="In Honor Of">IHO</abbr> Ms. Anita Garland</span>
</div>
完整页面代码: http: //pastebin.com/yFv2day1
对于当前使用的完整 javascript 代码:http: //pastebin.com/P0YVRuqY
我正在使用的资源:
- PHP
- jQuery 1.8.3
- 推特引导
提前感谢大家的时间和帮助。