【发布时间】:2016-12-22 05:48:36
【问题描述】:
我试图在 html 中获取这个按钮来创建一个新的字符串,但它没有做任何事情..
<html>
<head>
<title>Random Quote Generator</title>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="Reffference.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="row text-center">
<h1>Random Quote Generator</h1>
<div class="message">Click the button to generate a quote!</div>
<button id="getMessage" class="btn btn-primary">Click Me!</button>
</div>
</div>
</body>
</html>
这是文件 Reffference.js 中的 javascript
$(document).ready(function(){
$("#getMessage").on("click", function(){
$(".message").html("Here is the new generated text");
});
});
【问题讨论】:
-
在您的代码中看起来一切都很好。确保您的 jquery 正确加载到您的网页中。
-
嘿-您的代码很好,请确保您的js文件已完全加载并清除cookie
-
由于每个人都同意您的代码可以正常工作,因此如果没有更多信息,我们无法帮助您使其正常工作。您需要自己进行一些调试,尤其是让自己熟悉浏览器的开发人员工具并查找可能遇到的任何错误。
-
this fiddle 是您的代码,所有外部库都是您加载的内容 - 工作正常 - 检查
Reffference.js是否已加载(使用开发人员工具验证)跨度> -
在你的javascript中撒一些console.log消息,看看哪些输出到控制台,哪些不输出
标签: javascript html