我有以下 JavaScript 在 IE 中工作,但在 Chrome 和 Firefox 上不起作用。 这是代码:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#applicationSelect').change(function() {
document.getElementById('dropdown').value = "APPLICATION";
});
});
</script>
<input type="hidden" name="dropdown" value="" />
当我查看 Firebug 时,代码出现错误:
document.getElementById("dropdown") is null
document.getElementById('dropdown').value = "APPLICATION";
我需要你的建议。预先感谢您。
最佳答案
如果您已经在使用 jQuery,为什么不使用它来设置您的输入值:
$('#dropdown').val('APPLICATION');
正如其他人指出的,您输入的 id
不是“下拉菜单”。
另请注意,在大多数用例中,可以使用 $
代替 jQuery
。
关于javascript - document.getElementById 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9307390/