用方法函数进行一个随机名字的操作。
prop获取第一个与元素。
Math.random():
函数返回一个浮点数,伪随机数在范围从0 到小于1。
$(function() {
var name = ["张三", "李四", "王五", "赵六"];
var interval;
$("#start").click(function() {
$(this).prop("disabled", true);
$("#stop").prop("disabled", false);
interval = setInterval(function() {
var n = Math.floor(Math.random() * name.length);
$("#content").text(name[n]);
}, 20)
})
$("#stop").click(function() {
$(this).prop("disabled", true);
$("#start").prop("disabled", false);
clearInterval(interval);
var name = $("#content").text();
$("#big").text(name).hide;
})
})