Opera/Firefox Javascript 引擎差异
我想知道是否有其他人经历过使用 javascript 的浏览器之间的这种“故障”。
我的 javascript 如下,
var theForm = document.getElementById( 'theForm' );
theForm.firstname = theForm.firstName.value.trim();
theForm.lastname = theForm.lastName.value.trim();
theForm.firstName.style.color = "red";
这似乎在 Opera 11 中不起作用,但在 Firefox 4 中起作用。
我只是认为这两个 javascript 引擎处理事情的方式不同。
当我在两者中调试 javascript 时,我得到不同的结果。
在 Opera 中,theForm.firstName 在赋值后会变成常规的旧字符串,但在 Firefox 中它仍然是一个表单元素。
还有其他人经历过吗?
I wanted to know if anyone else has experienced this 'glitch' between browsers with javascript.
My javascript was the following
var theForm = document.getElementById( 'theForm' );
theForm.firstname = theForm.firstName.value.trim();
theForm.lastname = theForm.lastName.value.trim();
theForm.firstName.style.color = "red";
This doesn't seem to be working in Opera 11 but it works in Firefox 4.
I just think that the two javascript engines are handling things differently.
When I debug the javascript in both I get different results to.
In Opera, theForm.firstName turns into a regular old string after assignment but in Firefox it stays a form element.
Has anyone else experienced this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您隐藏了 form["someName"] ,浏览器如何知道它是表单内的属性还是 DOM 元素。
垃圾进来,垃圾出去。
How is a browser supposed to know whether form["someName"] is a property or a DOM element inside the form if you shadow it.
Garbage in, Garbage out.
就像 Raynos 所说:你正在将 DOM 元素设置为字符串。将您的代码更改为
Like Raynos said: You're setting a DOM element to a string. Change your code to be