2012-08-15 86 views
0

我希望我的iFrame窗口显示我从表单文本框输入的URL,我希望将iframe src =“”更改为表单域输入。我怎样才能做到这一点?这是我打算使用的示例代码。从表单输入输入iFrame源

<html> 
<head> 
<title>Blah.</title> 
<link href="style.css"rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<form> 
Enter URL: <input type="text" /> 
<input type="submit" value="GO" /> 
</form> 
<iframe src="" frameborder="0" marginwidth="0" scrolling="yes"></iframe> 
</body> 
</html> 

回答

1

试试这个。

<html> 
<head> 
    <title>Blah.</title> 
    <link href="style.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript"> 
     function SetSrc() 
     { 
      document.getElementById("myIfreme").src = document.getElementById("txtSRC").value; 
     } 
    </script> 
</head> 
<body> 
    <form> 
    Enter URL: 
    <input type="text" id="txtSRC" /> 
    <input type="button" value="GO" onclick="SetSrc()" /> 
    </form> 
    <iframe id="myIfreme" src="" frameborder="0" marginwidth="0" scrolling="yes"></iframe> 
</body> 
</html> 
+0

工程就像一个魅力!非常感谢 :) – C0dez 2012-08-15 18:53:54