gpt4 book ai didi

Javascript onblur 影响从文本框输入到 iframe 吗?

转载 作者:行者123 更新时间:2023-12-02 19:46:35 25 4
gpt4 key购买 nike

我试图在表单文本输入中输入一个网址,然后 onBlur 使用网址中指定的网页更新包含的 iframe 的内容。我似乎无法让它工作,我也不明白为什么......:)

有人可以帮助我吗?

这是代码...

<!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=iso-8859-1″ />
<script language="javascript" type="text/javascript" >
<!-- hide
function setIframeSource() {
var theSelect = document.getElementById('location');
var theIframe = document.getElementById('myIframe');
var theUrl;
theUrl = document.getElementById("location");
theIframe.src = theUrl;
}
// end hide -->
</script>
</head>
<body><center>
<form id="form1" method="post">
<input type="text" style="width:150px;" name="location2" id="location" onBlur="setIframeSource();">
</form>
<table width="100%" height="100%" border="1">
<tr>
<td width="300"><iframe src="http://www.ibm.com" id="myIframe" width="280" height="300" name="frame1"></iframe></td>
</tr>
</table>
</center>
</body>
</html>

最佳答案

function setIframeSource() {      
var theSelect = document.getElementById('location');
var theIframe = document.getElementById('myIframe');
var theUrl;
theUrl = document.getElementById("location");
theIframe.src = theUrl;
}

也许问题出在上面的第 5 行——它应该是:

theUrl = document.getElementById("location").value;

目前,您将输入元素本身分配给 theUrl,这不是 theIframe.src 的有效值!

关于Javascript onblur 影响从文本框输入到 iframe 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9811412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com