document.getElementById为null

Jem*_*mru 0 javascript jquery dom getelementbyid

我在IE中使用以下JavaScript,但在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="" />
Run Code Online (Sandbox Code Playgroud)

当我查看Firebug时,代码错误:

document.getElementById("dropdown") is null
document.getElementById('dropdown').value = "APPLICATION";
Run Code Online (Sandbox Code Playgroud)

我需要你的建议.先感谢您.

Mic*_*son 5

如果您已经使用jQuery,为什么不使用它来设置您的输入值:

$('#dropdown').val('APPLICATION');
Run Code Online (Sandbox Code Playgroud)

正如其他人所说,你的输入id不是"下拉".

另外,请注意,在大多数用例中可以使用一个$代替jQuery.