我想學習和創建一個jQuery的$("#answer")
並找到所有複選框裏面並檢查。例如,如果複選框#a1
被選中,則其他div(a2,a3,a4)被隱藏或者其他消息出來。如果我取消選中#a1
,所有div都會再次出現。 請指教我的代碼。裏面的ID部分找到所有的複選框,並檢查並隱藏其他未經檢查
<div id="answer">
<div id="a1">A.<input type="checkbox" name="a1" onclick="cbox()" ></input></div>
<div id="a2">B. <input type="checkbox" name="a2"onclick="cbox()"></input></div>
<div id="a3">C. <input type="checkbox" name="a3"onclick="cbox()"></input></div>
<div id="a4">D. <input type="checkbox" name="a4"onclick="cbox()"></input></div>
</div>
function cbox() {
if (this checkbox is checked) {
target other div inside (#answer) and add .hide()
}
}
2)是否有添加觸發器,我不需要使用onlick =「cbox」?
TQ
謝謝!我知道它是如何工作的! :) – user3418336
可以幫我觸摸切換複選框嗎?我只能檢查,但不能取消它現在:( – user3418336
你看到我的演示?複選框可以選中和取消選中。 – Felix