jQuery + client-side template = “Syntax error, unrecognized expression”

后端 未结 6 1032
离开以前
离开以前 2020-12-04 19:09

I just updated jQuery from 1.8.3 to 1.9, and it started crashing all of a sudden.

This is my template:



        
6条回答
  •  一向
    一向 (楼主)
    2020-12-04 19:23

    As the official document: As of 1.9, a string is only considered to be HTML if it starts with a less-than ("<") character. The Migrate plugin can be used to restore the pre-1.9 behavior.

    If a string is known to be HTML but may start with arbitrary text that is not an HTML tag, pass it to jQuery.parseHTML() which will return an array of DOM nodes representing the markup. A jQuery collection can be created from this, for example: $($.parseHTML(htmlString)). This would be considered best practice when processing HTML templates for example. Simple uses of literal strings such as $("

    Testing

    ").appendTo("body") are unaffected by this change.

提交回复
热议问题