JS in Dom and jquery $ test notes

Source: Internet
Author: User

A test dom and $ for the little Dongdong, just for keeping, not for anything else

The code is as follows Copy Code

The DOM is known

var J_top_bar = document.createelement ("div");

J_top_bar.style.cssText = ' Position:fixed;left:100px;top:100px;background-color: #fff; color: #000;p adding:10px; border:2px solid #09f; ';

Document.body.appendChild (J_top_bar);

J_top_bar.setattribute ("DATA-XL", 1);

j_top_bar.innerhtml = ' 1 ';


Js
function A (argument) {
Do not have to simulate, trapped for
var that = this;
if (!that._mark) {
That._mark = 1;
Manipulating Dom
that.innerhtml = that.innerhtml * 1 + 1;

That.setattribute ("XL", That.getattribute ("XL") * 1 + 1);
}

Delete that._mark;//Remove logo
}


//$
function B (argument) {

Simulate each click, because click inside to use $this = this;
var $this = JQuery (this);
if (! $this. Data ("Mark")) {
$this. Data ("Mark");

Manipulating Dom
$this. html (function (I, Val) {
Return val * 1 + 1;
}). attr ("Data-xl", $this. attr ("DATA-XL") * 1 + 1);

}

$this. Data ("Mark", 0);//Remove logo

}
var start = new Date-0;

Console.time ("Dom");
for (var i = 0;i<10000;i++) {
A.call (J_top_bar);
}
Console.timeend ("Dom");
Alert ("Dom:" + (new Date-0)-start)

start = new Date-0;

Console.time ("$");
for (var i = 0;i<10000;i++) {
B.call (J_top_bar);
}
Console.timeend ("$");
Alert ("$:" + ((new Date-0)-start)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.