我正在使用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的網址。
預先感謝您的時間和幫助!
我試着打在'的document.ready function'的功能,但它不工作。你能檢查我做錯了嗎? https://jsfiddle.net/hiWorld/a29bc42b/2/ – AlwaysANovice