【发布时间】:2018-06-18 01:15:03
【问题描述】:
我有一个名为myFunction 的函数,它是从DOM 调用的。
我也初始化了 jquery
<script>
$( document ).ready(function() {
function myFunction() {
window.open("survey.html");
}
$( "#begin" ).on("click", function() {
event.preventDefault();
console.log( "ready!" );
Materialize.toast('Be a friend!', 2000);
});
});
</script>
这是我的 HTML
<section class="jumbotron">
<div class="container">
<div class="row">
<div class="col s8 desc">
<h1>Welcome to Friend Finder</h1>
<h3>Take our survey find your match.</h3>
<a href="" id="begin" class="btn-large waves-effect waves-light red" onclick="setTimeout(myFunction, 3000);">BEGIN SEARCH</a><br>
</div>
</div>
</section>
我的目标:当我点击标签时。 IT 将调用函数 myFunction 并等待 3 秒 setTimeout 将浏览器转移到下一页
window.open(survey.html).
【问题讨论】:
-
去掉内联的
onclick... 并使用.on()来定义事件处理程序。
标签: javascript jquery html function scope