index.html 中的代码
<head>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body onload="loadIndex()">
<a id="registration" href="register.html"> Register </a>
</body>
index.js 中的代码
function loadIndex() {
alert("Page is loaded");
$("#registration").hide();
}
我收到警报,但链接并未隐藏。我有更多文件,但这在任何文件中都不起作用。我认为错误不在代码中,但我不知道错误在哪里。
最佳答案
除了一个微小的语法问题之外,您的代码很好。您只是缺少结束标记 </head>
。检查下面的代码:
function loadIndex() {
alert("Page is loaded");
$("#registration").hide();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body onload="loadIndex()">
<a id="registration" href="register.html"> Register </a>
</body>
关于javascript - jquery 中的 Hide() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46204927/