我的代码不起作用,请帮帮我 我想调用该函数并让它运行 ON ,当我再次调用它时, OFF 将被执行
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="container">
<div class="add-new-button">
<div class="add-new-button-label">
Add
</div>
<div class="add-new-button-icon">
<i class="fa fa-plus"></i>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
如果你使用布尔值来避免混淆,也许会更好
<html lang="es">
<head>
<title>Helping people at StackOverflow</title>
<script>
window.onload = function(){
// Start global "on" var in false/true state
var on = false;
function name (){
if(on != true){
// Set on state
on = true;
/* Execute "on" code rules
*/
}else{
// Set off state
on = false;
/* Execute "off" code rules
*/
}
console.log('Is "ON"?: ',on);
}
document.getElementById('btn').addEventListener('click',function(){
name();
});
}
</script>
</head>
<body>
<input id="btn" type="button" value='Ejecutar'>
</body>
</html>