有什么意见吗?当用户按下按钮时,最初隐藏的div必须显示在页面上。
<!DOCTYPE html>
<html>
<head>
<style>
div {
display: none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
function show() {
$("div").toggle();
}
</script>
</head>
<body>
<p>Animals are cute!</p>
<div><p>Some text gonna blow up some pixels!</p></div>
<button onclick="show()">Click</button>
</body>
</html>
控制台中确切写入的错误:
ReferenceError: show is not defined[Learn More
最佳答案
将内联脚本移到其自己的标签中。您不能在同一标记中使用外部脚本和内联脚本。
所以:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function show() {
$("div").toggle();
}
</script>
关于javascript - 未为我的简单按钮show-div javascript定义的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42514488/