use*_*527 4 html iframe src drop-down-menu
我可以通过"按钮"点击非常轻松地更改iframe的来源.但无论我尝试什么,我都无法通过使用下拉列表来实现同样的目标.
这有效:
<html>
<body>
<a href="google.com" target="iframe">google</a>
<iframe name="iframe" src="yahoo.ca"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但这不是:
<html>
<body>
<form name="change">
<select name="options" target="iframe">
<option><a href="google.com" target="iframe">google</a></option>
</select>
</form>
<iframe name="iframe" src="yahoo.ca"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激.我发现其他帖子类似,但都涉及阵列的使用 - 我不相信我应该需要?
BaB*_*L86 13
你需要使用JavaScript
<html>
<body>
<form name="change">
<SELECT NAME="options" ONCHANGE="document.getElementById('youriframe').src = this.options[this.selectedIndex].value">
<option>choise</option>
<option value="http://microsoft.com">Microsoft</option>
</SELECT>
<iframe name="iframe" id="youriframe" src="yahoo.ca"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)