简体   繁体   English

如何在按钮单击时运行js脚本

[英]How to run js script on button click

How to run this script with button click?如何通过单击按钮运行此脚本?

I don't know how to write code for a button and connect it with the code below.我不知道如何为按钮编写代码并将其与下面的代码连接。

<div id="rez" style="display: none;">BRAVO!</div> 

<script>
function showElement(id) {
    document.getElementById(id).style.display = "block";
}

window.onload = function ShowHide() {
    var legend = document.getElementById("LEGEND").innerHTML;

    if(legend.indexOf("100%") != -1) showElement("rez");

}
</script>

一个简单的谷歌搜索将产生这类问题的答案: http : //www.w3schools.com/jsref/event_onclick.asp

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

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