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

これでうまくいくはずです:

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

于 2012-08-08T13:50:28.567 に答える
2

使用する

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

また

if(!/\<input/i.test(value)) { ... }

後者は大文字と小文字を区別しないフラグが設定された正規表現です。

于 2012-08-08T13:50:32.017 に答える
1

状況によっては、明らかにjquery.is()関数を使用して要素をテストすることもできますhttp://api.jquery.com/is/

例えば

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