Home >Web Front-end >JS Tutorial >What should you pay attention to when using the [attribute^=value] selector in JQuery?
Notes1:
jQuerySelector [attribute^=value] usage notes under
One written before
var bindAttrs = $("[databind^='attr'", item);
is used in the script. Can everyone see the problem?
I have been using this script for a while, but I have never tested it in Firefox.
It can be used normally in other browsers!
Today someone suddenly discovered that the data loaded under Firefox was incorrect.
After a period of debugging, it was finally discovered that there was a problem with the code,
I made a stupid mistake. I only wrote the left bracket and forgot to write the right bracket.
Note 2:
Related HTML:
<div id="Zy_hotsort_img" class="Zy_hotsort_img"> <img src="${ctx}/images/resource/jpg02.jpg" databind="attr:{src:=http://{{newCourseware.coverpath}}}" > <div class="Zy_newicon">new</div> </div>
Related JS code:
var item = $("#<span style="font-family: Arial, Helvetica, sans-serif;">Zy_hotsort_img</span> <span style="font-family: Arial, Helvetica, sans-serif;">").html();</span> var bindAttrs = $("*[databind^='attr']", item);
A problem has arisen, it cannot be obtained like this databindAttribute is the img element starting with attr, so how should it be written?
Writing method one:
var item = $("#Zy_hotsort_img").prop("outerHTML"); var bindAttrs = $("*[databind^='attr']", item);
Writing method two:
var item = $("#Zy_hotsort_img").html(); var bindAttrs = $("*[databind^='attr']", $("<div></div>").append(item));
The above is the detailed content of What should you pay attention to when using the [attribute^=value] selector in JQuery?. For more information, please follow other related articles on the PHP Chinese website!