javascript.点击隐藏事件故障
javascript .hide on click event trouble
<header data-role="header">
<h1> TEA TIME </h1>
<a href="#home" class="ui-btn ui-btn-icon-top ui-icon-back ui-btn-icon-notext">back</a>
</header>
<h1>Takes 3 Minutes</h1>
<p id="timedisp">120 Sec</p>
<div class="clock">
</div>
<a href="#" id="start">Start</a>
<a href="#" id="reset">Reset</a>
</section>
下面是控制我的计时器的html
function greenTea(){
设置持续时间var持续时间=120;
Insert the duration into the div with a class of clock
$(".clock").html(duration + " sec");
Create a countdown interval
var countdown = setInterval(function () {
// subtract one from duration and test to see
// if duration is still above zero
if (--duration) {
// Update the clocks's message
$(".clock").html(duration + " sec");
// Otherwise
} else {
// Clear the countdown interval
clearInterval(countdown);
// set a completed message
$(".clock").html("End Your Steep");
}
// Run interval every 1000ms
}, 1000);
};
$("a#start").click(greenTea)
Why is the below not working? I am trying to get my p#timedisp to disappear when I click the a#start link.
$("p#timedisp").hide(("a#start").click());
$('#reset').click(function() {
location.reload();
});
您的jQuery应该是:
$('#start').click(function(){
$('#timedisp').hide();
})
您可以使用以下内容:
$(function() {
$("p#timedisp").on('click', function() {
//$("a#start").hide();
alert('do hide');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="timedisp">120 Sec</p>
如果您包含jQuery库,它应该可以工作
<a id="start" href="#">CLICK ME</a>
<p id="timedisp">120 Sec</p>
<script>
$(function() { // DOM is now ready
$("#start").click(function( event ) {
event.preventDefault(); // Prevent default anchor behavior
$("#timedisp").hide();
});
});
</script>
这将适用于
$('#start').on("click",function(){
document.getElementById('timedisp').style.display = 'none';
//post code
})
相关文章:
- 分派点击事件并保留击键修饰符
- 模糊事件的Javascript测试
- keyup事件处理程序更改焦点不适用于快速键入
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 如何使Javascript动态html表及其上的事件
- 使用类从一个标记中双击事件
- 如何在未直接触发的情况下停止事件
- 如何在elfinder插件(一个文件管理器插件)上获得上传前事件
- 对iPad上的点击事件反应缓慢
- 事件和状态
- Fancybox是否将Click事件静音
- 主干-不管怎样,检查事件以前是否绑定过
- 从控制器返回后Ajax启动事件激发
- javascript.点击隐藏事件故障
- Raphael悬停事件和调整大小框在第三次鼠标悬停后发生故障
- 如何从故障转移事件中获取源节点
- Javascript触摸事件故障
- 如何对触发两次的点击事件进行故障排除
- FastClick和click()事件触发故障
- 用于关键事件输入验证的Javascript正则表达式故障排除帮助