Javascript 如果选中复选框并用户单击按钮,则执行此操作
我有一个带有按钮的复选框,我希望当用户选中复选框并单击按钮时显示警报,当复选框未选中且用户单击按钮时执行其他操作 我做了一些事情,但我需要帮助来完成它。 非常感谢您的帮助Javascript 如果选中复选框并用户单击按钮,则执行此操作,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我有一个带有按钮的复选框,我希望当用户选中复选框并单击按钮时显示警报,当复选框未选中且用户单击按钮时执行其他操作 我做了一些事情,但我需要帮助来完成它。 非常感谢您的帮助 $(document).ready(function(e) { $('#remember').click(function() { if (this.checked) { alert("This is checked and you cliked"); } els
$(document).ready(function(e) {
$('#remember').click(function() {
if (this.checked) {
alert("This is checked and you cliked");
} else {
alert("This is unchecked and you cliked");
}
});
});
您可以为此使用jquery选择器:-
$('input[type="button"]').click(function() {
if ($('#remember').is(':checked')) {
alert("This is checked and you cliked");
} else {
alert("This is unchecked and you cliked");
}
});
您可以将id或类设置为按钮
$(document).ready(function(e) {
$('#btnEnter').click(function() {
if ($('#remember').is(':checked')) {
alert("This is checked and you cliked");
} else {
alert("This is unchecked and you cliked");
}
});
});
您正在复选框的onclick中显示警报。您需要在按钮的onClick中添加代码 看 希望这有帮助。使用
尝试用$'input[type=checkbox]'替换此.checked。是否:已选中。
$(document).ready(function(e) {
$('#buttonId').click(function() {
if ($('#remember').is(':checked')) {
alert("This is checked and you cliked");
} else {
alert("This is unchecked and you cliked");
}
});
});
$('[type=button]').click(function () {
if ($("#remember").prop("checked")) {
alert("This is checked and you cliked");
} else {
alert("This is unchecked and you cliked");
}
});
$(document).ready(function(e) {
$('#buttonId').click(function() {
if ($('#remember').prop('checked')) {
alert("This is checked and you cliked");
} else {
alert("This is unchecked and you cliked");
}
});
});