[英]Check whether checkbox is selected or not in bootstrap
我在這里使用檢查列表組-http://bootsnipp.com/snippets/featured/checked-list-group
我想檢查選中哪個復選框,並想通過單擊按鈕重置所有選中的項目。 我想用JavaScript做到這一點。
我使用常規的引導程序輸入標簽和Javascript成功實現了這一目標,但是以某種方式我無法在此代碼中實現。
<ul id="check-list-box" class="list-group checked-list-box">
<li class="list-group-item">Permutation</li>
<li class="list-group-item">Combination</li>
<li class="list-group-item">Probability</li>
</ul>
<button class="btn btn-primary" id="get-checked-data" onclick="myfunction()" >Get Checked Data</button>
<button class="btn btn-primary" id="reset" name="reset_all" >Reset</button>
這是我用javascript寫的:
function myfunction()
{
if(document.getElementById('check-list-box').checked)
{
alert("hello-world");
}
else
{
alert("not checked");
}
}
//And something similar for resetting. But I am sure, I am missing something here
一些幫助將不勝感激。
這是使用引導程序的蒙版HTML,看起來像一個復選框,但不是一個復選框。 因此您的代碼將永遠無法工作。
你你必須以這種方式工作
if($(".checked-list-box li.list-group-item-primary.active").length > 0){
alert("hello");
} else {
alert("not checked");
}
我在上面的代碼中寫的是,當您在上面的html中選中一個復選框時,li被添加了兩個類“ list-group-item-primary active”
因此,最好在li中獲得這些課程。 這將使您是否選中該復選框。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.