<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cat-1">
<h2>Micky</h2>
<p>Number of clicks: <span class="count-display"></span></p>
<img src="img/kitty.jpg" class="cat" data-counter>
</div>
<div class="cat-2">
<h2>John</h2>
<p>Number of clicks: <span class="count-display"></span></p>
<img src="img/kitty.jpg" class="cat" data-counter>
</div>
我想在单击按钮时执行两个操作。我上面的代码不起作用。请给出解决方案。
答案 0 :(得分:0)
只需调用本地javascript函数
<button type="button" onclick="myFunction();">Clear</button>
<script>
function myFunction()
{
document.getElementById('sun').innerHTML = '';
document.getElementById('sun1').innerHTML = 'Press to View';
}
</script>
答案 1 :(得分:0)
如果您有超过1行,请使用脚本标记
单独的用户定义函数
<!DOCTYPE html>
<html>
<head>
<script>
function clearbtn(){
document.getElementById('sun').innerHTML ='';
document.getElementById('sun1').innerHTML = 'Press to View';
}
function dateTime(){
document.getElementById('sun').innerHTML = Date();
document.getElementById('sun1').innerHTML = '';
}
</script>
</head>
<body>
<h2>DATE&TIME</h2>
<button type="button" onclick="dateTime()">View Date</button>
<p id="sun"></p>
<button type="button" onclick="clearbtn()">Clear</button>
<p id="sun1"></p>
</body>
</html>
答案 2 :(得分:0)
为您的按钮提供唯一ID
<button type="button" id="datebutt">View Date</button>
<p id="sun"></p>
<button type="button" id="clearbutt">Clear</button>
<p id="sun1"></p>
然后在你的脚本中你可以做
<script>
document.getElementById("datebutt").addEventListener("click",function(){
document.getElementById('sun').innerHTML = Date()`
},false);
document.getElementById("clear").addEventListener("click",function(){
document.getElementById('sun').innerHTML = '';
document.getElementById('sun1').innerHTML = 'Press to View';
},false);
</script>
答案 3 :(得分:0)
我有最好的解决方案
在js页面中: -
array
在Html页面中: -
fbauth2