我有一个显示产品列表的表格。
可以选择或取消选择每个产品。用户必须选择他的产品,然后点击继续(提交)按钮。
为了表示选择,我使用了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);
}
}
我正在使用 JSF 2.1 (Apache MyFaces 2.1.5)、JQuery 2.0.2,后端有一个 Java bean。如果有人可以帮助我,或者指出我做错了什么,我会超级棒的!