这段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> 展开
也就是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> 展开
2个回答
展开全部
这些你用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>
你要先引入一个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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询