用按钮控制iframe显示的网页实现方法

(编辑:jimmy 日期: 2024/10/11 浏览:2)

复制代码 代码如下:
//有两个按钮分别响应两个事件,用来控制iframe显示的网页。
<script type="text/javascript">
function bd(){
var baidu = document.getElementById("i");
baidu.src = "http://www.baidu.com";
}
function xl(){
var sina = document.getElementById("i");
sina.src = "http://www.sina.com.cn";
}
</script>
<style type="text/css">
#i{
width:400px;
height:300px;
}
</style>
</head>

<body>
<iframe id = "i" scrolling = "no">
</iframe>
<div>
<input type = "button" value ="百度" onclick = "bd()"/>
<input type = "button" value ="新浪" onclick = "xl()"/>
</div>
</body>