onClick将不能与onChange同时工作

onClick will not work at the same time as onChange

本文关键字:工作 onChange 不能 onClick      更新时间:2023-09-26

我已经尝试了几个小时来弄清楚我如何能与onchange目标iframe,然后当我点击按钮时,它会弹出一个新的窗口或选项卡。

function changeLocation(locationUrl)
{
 document.getElementById('iframetest').src=locationUrl
}
function subm()
{
var form = document.jump;
var value = document.jump.TSdropdown.options[document.jump.TSdropdown.selectedIndex].value;
document.getElementById('btn').onclick = function() {
    form.target = 'value';
    form.submit();
}
}
<form name="jump" method="post" action="" target="">
    <select name="TSdropdown" onchange="changeLocation(this.options[this.selectedIndex].value);">
    <option selected = "selected">Choose a Model Run</option>
    //option values
    <input class="button" type="button" id="btn" name="Submit" value="Submit" onclick="subm();">
    </select>
</form>
</td>
</tr>

<tr>
<td class="centered">
<div id="outerdiv">
<iframe height="400" width="940" name="iframetest" id="iframetest" src=""></iframe>
</div>
</td>
</tr>

没有id 'jump'的元素,请使用document.jump代替document.getElementById('jump');

获取所选下拉列表的值,使用:

var value = document.jump.TSdropdown.options[document.jump.TSdropdown.selectedIndex].value

现在使用value变量