我有一个表单,它将显示产品列表。
可以选择或取消选择每个产品。用户必须选择他的产品,然后点击continue(提交)按钮。
为了表示选择,我使用了http://www.bootstrap-switch.org/
我的问题是,当页面加载时,默认情况下会选择一些产品。
我拥有的代码如下:
<ui:repeat value="#{bean.products}" var="product" varStatus="status">
<li>
<div>
<div>
<div>
<div style="width: 100%;">
<div>
<div><b>#{product.productName}</b></div>
</div>
<div>
<div class="make-switch switch-mini " data-on-label="Yes" data-off-label="No">
<input class="switch#{status.index}" type="checkbox"></input>
</div>
<input type="hidden" class="checked#{status.index}" value="#{product.initiallySelected}"></input>
</div>
</div>
</div>
</div>
</div>
</li>
</ui:repeat>我有一个javascript,它需要将最初选择的产品标记为“选中”,但到目前为止,我没有尝试过任何东西。这是我的JS:
$(document).ready(function() {
flipSwitches(0);
}
function flipSwitches(index) {
if ($(".checked"+index).length != 0) {
var b = $(".checked"+index).val();
alert(b);
if (b == "true" || b == true) {
alert("selected");
// $(".switch"+index).attr('checked', true);
// $(".switch"+index).bootstrapSwitch('toggleStatus');
// $(".switch"+index).bootstrapSwitch('status');
// $(".switch"+index).bootstrapSwitch('setState', true);
}
flipSwitches(index+1);
}
}我使用的是JSF2.1(ApacheJava2.1.5),JQuery 2.0.2,在后端有一个Java bean。如果有人可以帮助我,或者指出我做错了什么,我将是超级的!
发布于 2013-10-25 17:12:59
将id添加到输入,即
<input id="myswitch" type="checkbox"/>然后您可以通过以下方式进行检查
if(status==true){
$('#myswitch').prop('checked',true);
}这就是我所做的,它对我很有效。
https://stackoverflow.com/questions/19360181
复制相似问题