这段HTML代码怎么将其中的JS段落分离出来,单独作为一个JS文件表达

这段HTML代码怎么将其中的JS段落分离出来,单独作为一个JS文件表达|也就是html用index.htmJS部分为test.js<!DOCTYPEhtmlPUBLIC"... 这段HTML代码怎么将其中的JS段落分离出来,单独作为一个JS文件表达|
也就是html用index.htm JS部分为test.js

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.holder{
position:absolute; border:solid #FF0000 1px; height:20px;
}
div .bar {
background-color:#003300; height:20px;
}
</style>
<script>

</script>
</head>

<body>
<span style="cursor:pointer;" onclick="document.getElementById('login').style.visibility = 'visible';">显示</span>
<div id="login" style="border:#003300 dotted 1px; margin:auto; width:200px; position:relative ">
<div style="cursor:pointer; position:absolute; right:2px; top:2px;" onclick="this.parentNode.style.visibility = 'hidden';">X</div>
<center><form>
Username:<input type="text" /></form>
Password:<input type="password" /><br />
<input type="submit" value="GO" />
</form>
</center>
</div>
</body>
</html>
展开
 我来答
liuzi0307
推荐于2017-12-16 · 超过47用户采纳过TA的回答
知道小有建树答主
回答量:113
采纳率:100%
帮助的人:133万
展开全部
这些你用jquery实现起来很方便。
你要先引入一个jquery得类库文件,代码如下(放在head中)
<script type="text/javascript" src=" http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
然后你的test.js文件这样写
//--js开始---
$(document).ready(function(){
$(".span1").click(function(){
$("#login").css("visibility","visible");
});
$(".div1").click(function(){
$("#login").css("visibility","hidden");
});
});
//--js结束---
HTML代码可以精简为:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.holder{
position:absolute; border:solid #FF0000 1px; height:20px;
}
div .bar {
background-color:#003300; height:20px;
}
</style>
<script type="text/javascript" src=" http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
<span style="cursor:pointer;" class="span1">显示</span>
<div id="login" style="border:#003300 dotted 1px; margin:auto; width:200px; position:relative ">
<div style="cursor:pointer; position:absolute; right:2px; top:2px;" class="div1">X</div>
<center><form>
Username:<input type="text" /></form>
Password:<input type="password" /><br />
<input type="submit" value="GO" />
</form>
</center>
</div>
</body>
</html>
ipint1
2010-05-27 · TA获得超过157个赞
知道答主
回答量:65
采纳率:0%
帮助的人:67.7万
展开全部
你这里什么都没有啊
<script>

</script>
你不会是把<body>里的onclick事件认为是js的吧。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式