繁体   English   中英

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

[英]When you click on the button, display a message

有一个复选框和一个按钮。 单击按钮时,如果单击复选框,则显示消息“谢谢”。 如果复选框未激活,则显示消息“再见”

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

这应该工作

<!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";
}

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


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

jQuery 版本

$('#button').on("click",function(){

    if( $('#checkBox').is(":checked")){
      alert("checked")
    }else{
      alert("un checked")
    }

})

 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>

 $("#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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM