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?

黄舟
Release: 2017-06-23 13:35:31
Original
1233 people have browsed it

Notes1:

jQuerySelector [attribute^=value] usage notes under

One written before

var bindAttrs = $("[databind^='attr'", item);
Copy after login

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>
Copy after login

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);
Copy after login

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);
Copy after login

Writing method two:

var item = $("#Zy_hotsort_img").html();  
var bindAttrs = $("*[databind^=&#39;attr&#39;]", $("<div></div>").append(item));
Copy after login

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!

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template