onclick继续调用javascript函数
HTML: 基本上,每当我点击这两个按钮中的任何一个,这个函数都会被反复调用。这是密码 我想我的问题是: 为什么要多次调用这些函数 我应该做些什么来阻止函数被多次调用,或者首先阻止它发生onclick继续调用javascript函数,javascript,html,onclick,Javascript,Html,Onclick,HTML: 基本上,每当我点击这两个按钮中的任何一个,这个函数都会被反复调用。这是密码 我想我的问题是: 为什么要多次调用这些函数 我应该做些什么来阻止函数被多次调用,或者首先阻止它发生 在chrome上,函数似乎只被调用一次。也许你的浏览器缓存了一个旧脚本:maiusc+f5来清理在Chrome 58上运行良好。是的,在firefox 53上也运行良好。@cancer,你完全正确。谢谢。@yuriy636谢谢您的检查。@Andreas也谢谢您的检查。发生这种情况的一种常见方式是,如果您在chr
在chrome上,函数似乎只被调用一次。也许你的浏览器缓存了一个旧脚本:maiusc+f5来清理在Chrome 58上运行良好。是的,在firefox 53上也运行良好。@cancer,你完全正确。谢谢。@yuriy636谢谢您的检查。@Andreas也谢谢您的检查。发生这种情况的一种常见方式是,如果您在chrome上打开了开发人员工具,并且仍在处理Js文件。在chrome上打开开发者工具可以启用缓存,您可以通过进入developertools->network->disable cache来解决这个问题
<div class="container-fluid">
<div class = "row text-center" align = "middle">
<h2>Pseudo Random Quote Machine</h2>
</div>
<div class = "row text-center" align = "middle">
<div class = "col-xs-12 well message" id = "quoting">
</div>
</div>
<div class = "row text-center" align = "middle">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Random Quote
</button>
<button id = "tweet" class = btn btn-primary>Tweet this!
</button>
</div>
</div>
</div>
function randomQuotes()
{
//array of quotes
var quotes = [ "\"Operator! Give me the number for 911!\" - Homer J. Simpson", "\"I\'m normally not a praying man, but if you\'re up there, please save me Superman\" - Homer J. Simpson", "\"I\'m in no condition to drive...wait! I shouldn\'t listen to myself, I\'m drunk!\" - Homer J. Simpson", "\"A Degenerate, Am I? Well You Are A Festizo. See, I Can Make Up Words Too, Sister\" - Peter Griffen", "\"Victory Shall Be Mine!\" - Stewie Griffen", "\"He's a spy, blow him up. I'm gonna go take a shit.\" - Rick Sanchez", "\"Ohh yea, you gotta get schwifty. \" - Rick Sanchez", "\"Yo! What up my glip glops!\" - Rick Sanchez", "\"WUBBA LUBBA DUB DUBS!!! \" - Rick Sanchez", "\"Existence is pain to a meeseeks Jerry, and we will do anything to alleviate that pain.\" - Mr. Meeseeks", " \"It\'s morphine time\" - TheRussianBadger"];
var randNum = Math.floor((Math.random() * quotes.length));
document.getElementById("quoting").innerHTML = quotes[randNum];
}
function tweetThis()
{
var tweetToShare = document.getElementById("quoting").innerHTML;
var tweetUrl = 'https://twitter.com/share?text=' + encodeURIComponent(tweetToShare) + ".";
window.open(tweetUrl);
}
document.getElementById("getMessage").onclick = function(){randomQuotes();}
document.getElementById("tweet").onclick = function(){tweetThis();}