使用输入类型text更改iframe-src
Change iframe src using input type text
我正在尝试使用输入中的url创建动态src chnge。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<form>
<input type="text" id="id">
<input type="button" value="Change site" onClick="newSite()">
</form>
<iframe id="iframe" src="www.google.com"></iframe>
<script type="text/javascript">
function newSite() {
var site = $('#id').val();
document.getElementById('iframe').src = "http://" + site;
}
</script>
</body>
</html>
所以我的问题是:如何通过按enter键发送表单?为什么它不起作用?
谢谢你的回答。
请在文本框中提供完整的url。
function newSite() {
var site = $('#id').val();
var iframe = document.getElementById('iframe');
iframe.src = site;
iframe.src = iframe.src;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<form>
<input type="text" id="id" />
<input type="button" value="Change site" onClick="newSite()" />
</form>
<iframe id="iframe" src="http://www.lipsum.com/" width="900" height='500'></iframe>
</body>
</html>
相关文章:
- 在不设置协议的情况下,使用javascript/jquery更改iframe-src
- 如何更改具有相同类、名称的 iframe src
- 用vbscript更改iframe src(打开关于语言)
- 使用输入类型text更改iframe-src
- 更改iframe src可阻止父级隐藏
- 使用 JavaScript 更改 iframe src
- 使用jquery检测iframe-src更改
- 通过选择框“选项”更改 Iframe SRC
- 使用 JavaScript 更改 iframe 的 src
- 如何更改 iframe src
- JavaScript 不会正确更改 iframe src
- 如何在跨域更改 iframe SRC URL 锚标记属性 target=_blank
- 更改 iframe src 并生效
- 如何在更改iframe-src时设置自定义http头
- 正在更改IFrame src属性
- 使用jQuery更改iframe src
- 通过js更改iframe-src
- 如何在不重新加载 iframe 的情况下更改 iframe src
- Javascript - 使用 switch 更改 iframe src
- jQuery-根据select值更改iframe-src