使用 IE9 设置表单输入值(出现错误 - 无法设置属性“值”的值:对象为 null 或未定义)
我的 PHP 代码如下所示:
<a id='next_page' HREF='#' onclick=\"javascript:document.getElementById('page_to_show').value='" . ($page + 1) . "'; return false;\" rel='facebox'>[Next $display_per_page]</a>
如您所见,我使用 document.getElementById('page_to_show').value
来设置隐藏字段“page_to_show”的值。我还尝试设置常规文本输入字段的值,并且遇到了相同的错误。我也尝试过 .Value
而不是 .value
- 没有运气。此代码适用于 IE8 和 FF 3.6.17。为什么不用IE9呢?这是声音代码,对吗?谢谢你!
哦,我也尝试过 jQuery 的 $("#page_to_show").val("Page Num");
方法,虽然它没有抛出 Javascript 错误,但它没有改变任何东西。
我还尝试了添加“”的临时修复,但这也不起作用!
My PHP code looks as such:
<a id='next_page' HREF='#' onclick=\"javascript:document.getElementById('page_to_show').value='" . ($page + 1) . "'; return false;\" rel='facebox'>[Next $display_per_page]</a>
As you can see, I am using document.getElementById('page_to_show').value
to set the value of the hidden field "page_to_show". I have also tried setting the value of a regular text input field, and I've encountered the same error. I've also tried .Value
instead of .value
- no luck. This code works in IE8 and FF 3.6.17. Why not IE9? It is sound code, correct? Thank you!
Oh, I've also tried jQuery's method of $("#page_to_show").val("Page Num");
and although it hasn't thrown a Javascript error,it doesn't change anything.
I've also tried a temp fix of adding "" however that didn't work either!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对你来说有些奇怪。这不是代码。该错误来自早期的代码,而不是我更新的代码。不管出于什么原因,IE9 没有刷新我的 PHP 代码!即使我按住 Shift 键并单击刷新,它也不会刷新我的代码。我必须退出浏览器并再次打开它才能刷新。也许这就是一个设定。谢谢你们!这就解释了为什么它如此奇怪以至于不起作用!
Here's something weird for ya. It wasn't the code. That error was from earlier code, not my updated code. For whatever reason, IE9 isn't refreshing my PHP code! Even if I shift-click refresh, it doesn't refresh my code. I had to exit the browser and open it again for it to refresh. Perhaps thats a setting. Thank you guys! That explains why it was so weird that it wasn't working!
您确定您的输入具有
id
而不仅仅是name
属性吗?此外,我发现 IE 在尝试设置
Are you certain that your input has an
id
and not just aname
attribute?Additionally, I've seen IE get sticky when trying to set the value of input fields that exist outside of a
<form>
.