单击按钮时,显示一条消息

时间:2017-11-24 20:00:16

标签: javascript jquery

有一个复选框和一个按钮。当您单击按钮时,显示消息"谢谢"如果单击该复选框。如果该复选框未激活,则显示消息" Goodbye"

<input  type="checkbox" id="checkBox">
<input type="button" id='button'>

5 个答案:

答案 0 :(得分:0)

这应该有效

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
 <input  type="checkbox" id="checkBox">
<input type="button" id='button' value = "Click me" onclick="FbotonOn()">
<p id="texto"></p>
</body>
</html>

<script type="text/javascript">
function FbotonOn() { 

    if(document.getElementById('checkBox').checked)
        document.getElementById('texto').innerHTML = "Thank you";
    else
        document.getElementById('texto').innerHTML = "Good Bye";
}

答案 1 :(得分:0)

document.getElementById("checkBox").addEventListener("click,", function(){ 
console.log("check box click")});


document.getElementById("button").addEventListener("click,", function(){ console.log("button click")});

答案 2 :(得分:0)

Jquery版本

*** Running FRONTEND component engine specs
Run options: --seed 29704

# Running:

......................................................................................................................................................................................E...........

答案 3 :(得分:0)

var checkboxTrue = "CheckBox is checked";
var checkboxFalse = "Please click on the checkbox";

function check() { 

    if(document.getElementById('checkBox').checked) {
        alert(checkboxTrue);
}
    else {
        alert(checkboxFalse);
}
}
<!DOCTYPE html>
<html>
<head>
<title> CheckBox </title>
</head>
<body>
<input type="checkbox" id="checkBox">
<input type="button" id='button' value ="Click me" onclick="check()">
</body>
</html>

答案 4 :(得分:0)

$("#btnSubmit").click(function(){

 var checkoutHistory = document.getElementById('ChkCheck');
    if (checkoutHistory.checked) {

alert("Ok");
}
else{
alert("Check box not selected");
}
})
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<html>
<head>
</head>
<body>
<input type="checkbox" id="ChkCheck">
<input type="submit" value="submit" id="btnSubmit">
</body>
</html>