日期:2014-05-16 浏览次数:20552 次
<!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" >
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
<title>无标题页</title>
<style>
#frame{
widows:400px;
height:200px;
border:1px solid red;
}
</style>
<script src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#baidu").click(function(){
var src = $(this).attr("title");
alert(src)
$("#frame").attr("src",src);
});
$("#guge").click(function(){
var src = $(this).attr("title");
alert(src)
$("#frame").attr("src",src);
});
});
</script>
</head>
<body>
<iframe id="frame">
</iframe>
<a href="#" id="baidu" title="http://www.baidu.com">百度</a>
<a href="#" id="guge" title="http://www.google.com">谷歌</a>
</body>
</html>
------解决方案--------------------
在lieri111的基础上稍微修改下:
<!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" >
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<head>
<title>无标题页</title>
<style>
#frame{
widows:400px;
height:200px;
border:1px solid red;
}
</style>
<script type="text/javascript">
function opensrc(obj){
var src = obj.title;
var iframeSrc = document.getElementById("frame").src;
if("baidu" == this.id)
{
document.getElementById("guge").title = iframeSrc;
}
else
{
document.getElementById("baidu").title = iframeSrc;
}
document.getElementById("frame").src = src;
}
</script>
</head>
<body>
<iframe id="frame"></iframe>
<a href="#" id="baidu" onclick="opensrc(this)" title="http://www.baidu.com">百度</a>
<a href="#" id="guge" onclick="opensrc(this)" title="http://www.google.com">谷歌</a>
</body>
</html>