我正在使用Bootstrap Switch在切换开关中打开我的复选框。
现在我想根据开关是打开还是关闭来显示不同的消息。听起来很简单......但我似乎无法让它工作:(
我的 HTML:
<div class="approve-delivery">
<label for="config-email" class="control-label col-xs-5">
Do you want to send out email?
</label>
<input type="checkbox" id="config-email" onclick="ToggleSwitchMessage('config-email', 'enable-msg', 'disable-msg')" checked/>
</div>
<div class="email-config-msg">
<p id="enable-msg">
All emails will be sent.
</p>
<p id="disable-msg">
No email will be sent.<br/>
Please remember, you must turn email ON again if you want emails to
be sent during this login session.
</p>
</div>
还有我的 jQuery:
function ToggleSwitchMessage(checkId, firstCommentId, secondCommentId) {
var check_box = document.getElementById(checkId)
var first_alert = document.getElementById(firstCommentId);
var second_alert = document.getElementById(secondCommentId);
if (check_box.checked == true) {
first_alert.style.visibility = "visible";
first_alert.style.display = "inline-block";
second_alert.style.visibility = "hidden";
second_alert.style.display = "none";
} else {
first_alert.style.visibility = "hidden";
first_alert.style.display = "none";
second_alert.style.visibility = "visible";
second_alert.style.display = "inline-block";
}
}
这是我工作的JSFiddle
同样,这就是我想要做的:
- 根据选中/未选中的复选框,加载时应在页面上显示正确的消息
- 然后如果复选框的选项被更改,它应该显示适当的消息
我希望我说得通(英语不是我的第一语言)!如果是重复的问题,我也很抱歉,在这种情况下,请提供 Q/A(s) 的 URL。
提前感谢您的时间和帮助!