[英]Uppercase tags in Internet Explorer 8
I have an HTML manipulation issue that manifests itself only in IE8. 我有一个HTML操作问题,仅在IE8中表现出来。
I had recently written some javascript that analysed a tag and did something depending on what it was. 我最近写了一些JavaScript,该Javascript分析了标签并根据标签的内容进行了处理。
The piece of code assumed the tag was in lowercase. 这段代码假定标签是小写的。
if(value.indexOf('<input') == -1)
This failed under IE8 and I have to fix it. 在IE8下失败了,我必须修复它。
Now I could and a second check as follows: 现在,我可以进行第二次检查,如下所示:
if(value.indexOf('<input') == -1 && value.indexOf('<INPUT') == -1)
This will catch both possibilities, but seems awfully messy. 这将抓住两种可能性,但看起来非常混乱。
Is there a better way to deal with this situation? 有没有更好的方法来处理这种情况? Could JQuery deal with this?
JQuery可以处理吗?
"value" is an html string passed to my javascript function from JQGrid. “值”是从JQGrid传递到我的javascript函数的html字符串。 Using IE8 the string is uppercase, using IE9, FF, Chrome, it is lowercase.
使用IE8,字符串为大写,使用IE9,FF,Chrome,则为小写。
这应该可以解决问题:
if(value.toLowerCase().indexOf('<input') == -1)
Use 采用
if(value.toLowerCase().indexOf('<input') == -1) { ... }
or 要么
if(!/\<input/i.test(value)) { ... }
The latter being a regular expression with the ignore case flag set. 后者是设置了忽略大小写标志的正则表达式。
Depending on your situation obviously you could also use jquery .is()
function to test for an element http://api.jquery.com/is/ 显然,根据您的情况,您还可以使用jquery
.is()
函数测试元素http://api.jquery.com/is/
for instance 例如
$target.is("input")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.