Is JQuery(..).html() buggy in jQuery 1.3.2?

后端 未结 2 752
闹比i
闹比i 2021-01-18 00:36

The code here does not return what one expects:

jQuery(\'
Look here: [ jQuery0=\"null\" ]
\').html()

Rather, you get:

相关标签:
2条回答
  • 2021-01-18 00:53

    What would be the motivation behind the .replace?

    To hide attributes that jQuery is using for internal purposes.

    code like this makes me wonder if I should use jQuery in production at all.

    Yes, I had the exact same reaction. It's just incredibly sloppy. Trying to process HTML with regexp is the kind of naïve hack you expect from first-time question posters, not the sort of behaviour you'd hope to see in the framework so many SO users appear to worship.

    It's not the only place where jQuery trips up by trying to parse markup with regex; some of the selector stuff is broken too. These may be obscure corner cases, but to me it's a huge red flag indicative of the wrong approach.

    0 讨论(0)
  • 2021-01-18 01:00

    This code is new in 1.3.2, it wasn't in 1.3.1. It looks to me like jQuery uses attributes whose names start with "jQuery" to store data on elements, and this is its way of not exposing that to you when you ask for the html back.

    It clearly isn't a bug. The author intended to remove that HTML before returning you the string.

    Does this affect your code? As with any library, you should test your production code thoroughly before deploying it.

    0 讨论(0)
提交回复
热议问题