admin管理员组文章数量:1241160
I have this code placed in index.html, all together - Javascript and HTML. what I want is to place the JS into another, separate file called "pw.js".
I have created a blank JS file located in folder "js". I have added it to (head) as well like this <script src="js/pw.js"></script>
This is what I have now in index.html, how to place the JS separatly? Please be specific in answers, I'm a beginner.
<script type="text/javascript">
function isValid(){
var password = document.getElementById('password').value;
if (password == "123")
top.location.href="./file.pdf";
else
{window.location.reload();}
}
</script>
<div class="field_pw">
<form name="PasswordField" action="">
Password:
<input type="password" id="password" name="password" class="noborder" style="font-size: 25px">
<input type="button" class="button_pw" value="download" onclick="isValid();">
</form>
</div>
I have this code placed in index.html, all together - Javascript and HTML. what I want is to place the JS into another, separate file called "pw.js".
I have created a blank JS file located in folder "js". I have added it to (head) as well like this <script src="js/pw.js"></script>
This is what I have now in index.html, how to place the JS separatly? Please be specific in answers, I'm a beginner.
<script type="text/javascript">
function isValid(){
var password = document.getElementById('password').value;
if (password == "123")
top.location.href="./file.pdf";
else
{window.location.reload();}
}
</script>
<div class="field_pw">
<form name="PasswordField" action="">
Password:
<input type="password" id="password" name="password" class="noborder" style="font-size: 25px">
<input type="button" class="button_pw" value="download" onclick="isValid();">
</form>
</div>
Share
Improve this question
edited Aug 24, 2015 at 20:39
Paul Roub
36.4k27 gold badges86 silver badges95 bronze badges
asked Aug 24, 2015 at 20:31
IgorsIgors
931 gold badge1 silver badge6 bronze badges
3
- 2 get all between <script> tags and make new file from it. Then use <script src="...path to your file"></script> – bksi Commented Aug 24, 2015 at 20:33
-
1
Don't put the
<script>
tags in your JavaScript file. – Pointy Commented Aug 24, 2015 at 20:34 - Note that it is better to make ajax call to secure your password via server side script (db or whatever) – bksi Commented Aug 25, 2015 at 1:33
1 Answer
Reset to default 10your pw.js file in js folder:
function isValid() {
var password = document.getElementById('password').value;
if (password == "123")
top.location.href="./file.pdf";
else
window.location.reload();
}
your html file:
<script type="text/javascript" src="js/pw.js"></script>
<div class="field_pw">
<form name="PasswordField" action="">
Password:
<input type="password" id="password" name="password" class="noborder" style="font-size: 25px">
<input type="button" class="button_pw" value="download" onclick="isValid();">
</form>
</div>
本文标签: How to place Javascript in a separate file from HTMLStack Overflow
版权声明:本文标题:How to place Javascript in a separate file from HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739999509a2219510.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论