jQuery on() 方法
jQuery on() Method
我无法完成这项工作,我已经阅读了我能找到的有关该主题的所有内容。你当然可以帮助我。
我只需要带有 id "next" 的按钮在单击时在控制台上登录一个随机数..她是按钮的 html:
<button id= "next" type= "button" class= "btn btn-lg col-xs-1">Quote!</button>
这是 js:
$(document).ready(function(){
$("#next").on("click", function(){
var randomNum = Math.floor((Math.random()*8)+1);
console.log(randomNum);
});
});
(为了清楚起见,我删减了代码)。
谢谢!
$(document).ready(function(){
$("#next").on("click", function(){
var randomNum = Math.floor((Math.random()*8)+1);
console.log(randomNum);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id= "next" type= "button" class= "btn btn-lg col-xs-1">Quote!</button>
给你。似乎工作正常。
请确保在调用代码之前包含 JQuery,否则您将收到引用错误。
编码愉快!
我无法完成这项工作,我已经阅读了我能找到的有关该主题的所有内容。你当然可以帮助我。 我只需要带有 id "next" 的按钮在单击时在控制台上登录一个随机数..她是按钮的 html:
<button id= "next" type= "button" class= "btn btn-lg col-xs-1">Quote!</button>
这是 js:
$(document).ready(function(){
$("#next").on("click", function(){
var randomNum = Math.floor((Math.random()*8)+1);
console.log(randomNum);
});
});
(为了清楚起见,我删减了代码)。 谢谢!
$(document).ready(function(){
$("#next").on("click", function(){
var randomNum = Math.floor((Math.random()*8)+1);
console.log(randomNum);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id= "next" type= "button" class= "btn btn-lg col-xs-1">Quote!</button>
给你。似乎工作正常。 请确保在调用代码之前包含 JQuery,否则您将收到引用错误。 编码愉快!