我被迫利用jQuery Mobile和我有一些犹豫,即使它是一个非常良好的系统。所以,我有一个表单,当任何复选框更改时提交。客户端需要它,以便当他们单击页面时等待提交一段时间,所以如果选择了另一个页面,则先前的请求不会被触发,新的请求也不会被触发。它本质上是使它不那么即时,并允许更有效的过滤/请求。我的代码是像这样:多个复选框选择与延迟检查其他复选框更改
$(function() {
var sForm = "form[name='Waves']",
sCboxes = "input[type='checkbox']",
sWaves = "";
var $Cboxes = $(sForm + " " + sCboxes),
sChecked = sCboxes + ":checked";
$Cboxes.change(function(event) {
var $this = $(this);
if ($this.attr("id") != "ClearAll") {
console.debug($(this));
console.debug('Changing page.');
sWaves = "";
// Form the string for the selected waves with standard check-if-it's-the-last
// element logic for comma generation.
$.each($(sChecked) , function(i, v) {
var $this = $(this);
var iIndex = v.value;
sWaves += iIndex + ((i == $(sChecked).length - 1) ? "" : ",");
});
console.debug("Waves to select: " + sWaves);
$.mobile.changePage("default.asp", {
data: { Wave: sWaves }, // Submit the previously formed string
type: "post"
});
//$(sForm).submit();
} else {
$(sChecked).add($(this)).attr("checked", false).checkboxradio("refresh");
$.mobile.changePage("default.asp", {
data: { Wave: "" },
type: "post"
});
}
});
$("#ClearAll").click(function(event) {
event.preventDefault();
});
$(".slideout").click(function(){
$(this).parents(".ui-collapsible").find(".ui-icon-minus").click();
});
});
该窗体的HTML:
<form ACTION="<%=ASP_SELF()%>" ID="Waves" METHOD="post" NAME="Waves">
<% ' Put the scripts we need here so that it loads with the page. %>
<script SRC="/base/scripts/scripts.js"></script>
<fieldset DATA-ROLE="controlgroup" DATA-TYPE="horizontal" STYLE="margin-left:5px; margin-bottom:0px; ">
<input TYPE="checkbox" NAME="#" ID="#" VALUE="Select Waves" CLASS="custom" />
<label CLASS="no-hover" FOR="#"> Waves: </label>
<input TYPE="checkbox" NAME="Wave1" ID="Wave1" VALUE="1" CLASS="custom" STYLE="width:70px !important; " <% If Instr(request("Wave"),"1") OR WaveOne = "YES" Then response.write " checked=""checked""" End If %> />
<label FOR="Wave1"> 1 </label>
<input TYPE="checkbox" NAME="Wave2" ID="Wave2" VALUE="2" CLASS="custom" STYLE="width:70px !important; " <% If Instr(request("Wave"),"2") OR WaveTwo = "YES" Then response.write " checked=""checked""" End If %> />
<label FOR="Wave2"> 2 </label>
<input TYPE="checkbox" NAME="Wave3" ID="Wave3" VALUE="3" CLASS="custom" STYLE="width:70px !important; "<% If Instr(request("Wave"),"3") OR WaveThree = "YES" Then response.write " checked=""checked""" End If %> />
<label FOR="Wave3"> 3 </label>
<input TYPE="checkbox" NAME="Wave4" ID="Wave4" VALUE="4" CLASS="custom" STYLE="width:70px !important; "<% If Instr(request("Wave"),"4") OR WaveFour = "YES" Then response.write " checked=""checked""" End If %> />
<label FOR="Wave4"> 4 </label>
<input TYPE="checkbox" NAME="ClearAll" ID="ClearAll" VALUE="Clear" CLASS="custom" $('input[data-type="search"]').TRIGGER("CHANGE").VAL(""); />
<label FOR="ClearAll"> Clear </label>
</fieldset>
</form>
我需要延迟$.mobile.changePage
调用足够长的时间,以允许其他相关的复选框(在同一字段集内)也被切换。我感谢任何输入!这是一件非常重要的事情。
非常爱。我讨厌定时器> :( – 2012-07-18 22:53:43