0

I have an HTML manipulation issue that manifests itself only in IE8.

I had recently written some javascript that analysed a tag and did something depending on what it was.

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.

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?

"value" is an html string passed to my javascript function from JQGrid. Using IE8 the string is uppercase, using IE9, FF, Chrome, it is lowercase.

4

3 回答 3

3

This should do the trick:

if(value.toLowerCase().indexOf('<input') == -1)

于 2012-08-08T13:50:28.567 回答
2

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.

于 2012-08-08T13:50:32.017 回答
1

Depending on your situation obviously you could also use jquery .is() function to test for an element http://api.jquery.com/is/

for instance

$target.is("input")
于 2012-08-08T13:52:53.450 回答