JS中如何控制 超级链接 来打开 模式窗口
如:<aid="aAddress"href=""name="aAddress">填写你的邮寄地址</a>当我按下这个链接后让它打开一个模式窗口.这怎么写JS...
如: <a id="aAddress" href="" name="aAddress">填写你的邮寄地址</a>
当我按下这个链接后 让它打开一个模式窗口.这怎么写JS 展开
当我按下这个链接后 让它打开一个模式窗口.这怎么写JS 展开
展开全部
1、使所有的窗口都在子窗口打开
<script language="javascript">
//跳到新窗口
function externallinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName_r("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href"))
anchor.target = "_blank";
}
}
window.onload = externallinks;
</script>
2、超链接,一部分在本窗口打开,大部分在新窗口打开
只要在超链接那设置target="_self",并改为如下:
<script language="javascript">
function externallinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName_r("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("target")!='_self')
anchor.target = "_blank";
}
}
window.onload = externallinks;
</script>
3、这是用jquery,让其所有超链接在新窗口打开
<script type="text/javascript" src="JQuery/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a").attr("target","_blank");
})
</script>
4、用jquery,想让一部分超链接在新窗口打开,只要在基范围加个id就好了,比如,<div id="ccc"><a href="index.html">首页</a></div>
<script type="text/javascript" src="JQuery/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("div#ccc a").attr("target","_blank");
})
</script>
<script language="javascript">
//跳到新窗口
function externallinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName_r("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href"))
anchor.target = "_blank";
}
}
window.onload = externallinks;
</script>
2、超链接,一部分在本窗口打开,大部分在新窗口打开
只要在超链接那设置target="_self",并改为如下:
<script language="javascript">
function externallinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName_r("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("target")!='_self')
anchor.target = "_blank";
}
}
window.onload = externallinks;
</script>
3、这是用jquery,让其所有超链接在新窗口打开
<script type="text/javascript" src="JQuery/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a").attr("target","_blank");
})
</script>
4、用jquery,想让一部分超链接在新窗口打开,只要在基范围加个id就好了,比如,<div id="ccc"><a href="index.html">首页</a></div>
<script type="text/javascript" src="JQuery/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("div#ccc a").attr("target","_blank");
})
</script>
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/JavaScript">
window.onload = function() {
if (!document.getElementsByTagName) return false;
var lnks = document.getElementsByTagName("a");
for (var i=0; i<lnks.length; i++) {
if (lnks[i].getAttribute("class") == "popup") {
lnks[i].onclick = function() {
popUp(this.getAttribute("href"));
return false;
}
}
}
}
function popUp(winURL) {
window.open(winURL,"popup","width=320,height=480");
}
</script>
</head>
<body>
<a href="http://www.example.com/" class="popup">填写你的邮寄地址</a>
</body>
</html>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/JavaScript">
window.onload = function() {
if (!document.getElementsByTagName) return false;
var lnks = document.getElementsByTagName("a");
for (var i=0; i<lnks.length; i++) {
if (lnks[i].getAttribute("class") == "popup") {
lnks[i].onclick = function() {
popUp(this.getAttribute("href"));
return false;
}
}
}
}
function popUp(winURL) {
window.open(winURL,"popup","width=320,height=480");
}
</script>
</head>
<body>
<a href="http://www.example.com/" class="popup">填写你的邮寄地址</a>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询