简体   繁体   English

IE9分配的值不同于IE Quirks模式

[英]IE9 Assigning Different Value than IE Quirks Mode

I'm using javascript to dynamically assign values to some html elements 我正在使用JavaScript将值动态分配给某些html元素

var newInput = document.getElementById('newInput1');
var oldInput = document.getElementById('oldInput1');

newInput.value = oldInput.firstChild.nodeValue;

When I run this in IE Quirks Mode, my value is returned appropriately. 当我在IE Quirks模式下运行此命令时,将适当返回我的值。 My debugger will read: 我的调试器将显示为:

Name      |  Value
newInput  |  777

however, in IE9 I'll sometimes get: 但是,在IE9中,有时会得到:

Name      |  Value
newInput  |  "\n   \n  777\n"

I haven't encountered this problem before; 我以前没有遇到过这个问题; has .firstChild or .nodeValue been replaced in IE9? IE9中是否已替换了.firstChild.nodeValue

Edit 编辑

I've noticed while assigning newInput.value, a single space " " is added to the string. 我在分配newInput.value时注意到,在字符串中添加了一个空格" " This space is .trim med later in the code, but perhaps IE9 can't accept it at some point or another 该空间在代码的后面部分是.trim ,但是IE9可能无法在某些时候接受它

oldInput.firstChild.nodeValue.trim(); //to remove extra new line

The trim() method removes whitespace from both sides of a string. trim()方法从字符串的两侧删除空格。

Note: The trim() method does not change the original string. 注意: trim()方法不会更改原始字符串。

see this reference 看到这个参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM