Home >Web Front-end >JS Tutorial >What should you pay attention to when using the [attribute^=value] selector in JQuery?

What should you pay attention to when using the [attribute^=value] selector in JQuery?

黄舟
黄舟Original
2017-06-23 13:35:311224browse

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^=&#39;attr&#39;]", 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^=&#39;attr&#39;]", item);

Writing method two:

var item = $("#Zy_hotsort_img").html();  
var bindAttrs = $("*[databind^=&#39;attr&#39;]", $("<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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn