【发布时间】:2019-10-10 02:42:53
【问题描述】:
我正在尝试使用 HTML 表单元素(特别是选择下拉菜单)来更新嵌入在页面上的 iframe 的 URL 路径。这应该会在每次进行不同的选择时重新加载 iframe。
我已经尝试使用 Javascript 函数在 onkeyup 或 onmouseup 事件发生时传递 select 的值,但我没有看到发生这种情况时发生任何变化:
<!DOCTYPE html>
<head>
<style>
* {font-family: arial;}
</style>
<script type="text/javascript">
window.onload = function() {
document.monthyear.onkeyup = my;
document.monthyear.onmouseup = my;
};
function my() {
var my = String(document.monthyear.value);
document.getElementById("iframe").src = my;
};
</script>
</head>
<body>
<select name="monthyear">
<option value="/258001">
January 2019
</option>
<option value="/258002">
February 2019
</option>
<option value="/258003">
March 2019
</option>
<option value="/258004">
April 2019
</option>
</select>
<h1>Month</h1><iframe allowfullscreen frameborder="0" height="450" id="iframe" src="https://www.example.com/258001" style="border:0" width="800"></iframe>
【问题讨论】:
-
你使用
document.getElementById("my").value,但是哪里有id为"my"的元素? -
抱歉,现已编辑。
标签: javascript html forms drop-down-menu src