如何使用iframe更改iframe的src? [英] How do I make it so the src of an iframe changes with javascript?

查看:119
本文介绍了如何使用iframe更改iframe的src?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:



< iframe id =wwwname =wwwsrc =about:blank>< / iframe> ;



< script>

函数myFunction(){

var userInput = prompt(输入URL ,);

if(userInput!= null && userInput!=){document.getElementByID('www')。src = userInput;}}

myFunction();

< / script>



src不会改变。请问你能解释一下我做错了什么吗?

My code is:

"<iframe id="www" name="www" src="about:blank"></iframe>

<script>
function myFunction(){
var userInput = prompt("Enter URL","");
if(userInput !=null && userInput !=""){document.getElementByID('www').src=userInput;}}
myFunction();
</script>"

The src won't change. Please can you explain what I'm doing wrong?

推荐答案

javascript是区分大小写的,你的getElementByID中的情况不正确,这就是代码无效的原因。请在下面试试



javascript is case sensitive and cases in your "getElementByID" are not proper that's why code is not working. Please try below

document.getElementById('www').src=userInput;


这篇关于如何使用iframe更改iframe的src?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆