配列を介して文字列のスプライスを拡張すると、簡単にパフォーマンスの問題が発生する可能性があります
function StringBuffer() {
This.__strings__ = new Array();
}
StringBuffer.prototype.append = function (str) {
This.__strings__.push(str);
これを返してください;
}
StringBuffer.prototype.toString = function () {
this.__strings__.join("");
を返します。 }
varbuffer = new StringBuffer();
buffer.append("Hello ").append("javascript");
var result =buffer.toString();
アラート(結果); // こんにちは javascript
コードソース: https://gist.github.com/hehongwei44/fe71f10e4d2d9295aeab
ページビューポートのスクロールバーの位置に関する補助機能
/*現在のページの高さと幅を決定する 2 つの関数*/
関数 pageHeight() {
document.body.scrollHeight;
を返します }
関数 pageWidth() {
document.body.scrollWidth;
を返します }
/*スクロールバーの水平位置と垂直位置を決定します*/
関数scrollX() {
var de = document.documentElement;
self.pageXOffset を返します || (de && de.scrollLeft) || }
関数scrollY() {
var de = document.documentElement;
self.pageYOffset を返します || (de && de.scrollTop) || }
/*ブラウザのビューポートの高さと幅を決定する 2 つの関数*/
関数 windowHeight() {
var de = document.documentElement;
self.innerHeight を返します || (de && de.clientHeight) || document.body.clientHeight;
}
関数 windowWidth() {
var de = document.documentElement;
self.innerWidth を返します || (de && de.clientWidth) || document.body.clientWidth;
}
//IE は透明度を処理します
If (elem.filters) {
elem.style.filters = 'alpha(opacity=' level ')';
} else {
elem.style.opacity = レベル / 100;
}
}
e = e || ウィンドウ.イベント;
e.pageX || e.clientX document.body.scrollLeft;
を返す }
関数 getY(e) {
e = e || ウィンドウ.イベント;
e.pageY || e.clientY document.body.scrollTop;
を返す }
/*現在の要素に対する相対的なマウスの位置を取得する 2 つの関数*/
関数 getElementX(e) {
戻り値 (e && e.layerX) || window.event.offsetX;
}
関数 getElementY(e) {
戻り値 (e && e.layerY) || window.event.offsetY;
}
/**
* Use display to hide elements
**/
function hide(elem) {
var curDisplay = getStyle(elem, 'display');
if (curDisplay != 'none') {
elem.$oldDisplay = curDisplay;
}
elem.style.display = 'none';
}
/**
* Use display to display the function of elements
**/
function show(elem) {
elem.style.display = elem.$oldDisplay || '';
}
Code source: https://gist.github.com/hehongwei44/b4192af8227d756bfda6
General functions related to style
/**
* Get the style attribute (name) of the specified element (elem)
**/
function getStyle(elem, name) {
//If it exists in style[], then it has been set (and is current)
If (elem.style[name]) {
return elem.style[name];
}
//Otherwise, how to test IE
else if (elem.currentStyle) {
return elem.currentStyle[name];
}
//Or W3C method
else if(document.defaultView && document.defaultView.getComputedStyle){
name = name.replace(/(A-Z)/g, "-$1");
name = name.toLowerCase();
var s = document.defaultView.getComputedStyle(elem, "");
return s && s.getPropertyValue(name);
}
//Otherwise, the user is using another browser
else {
return null;
}
}
Code source: https://gist.github.com/hehongwei44/9abf63536accd0f2eeb7
Get the current height and width of the element
/**
* Get the true height of the element
* See the above function for dependent getStyle.
**/
function getHeight(elem) {
Return parseInt(getStyle(elem, 'height'));
}
/**
* Get the real width of the element
* For the dependent getStyle, see the function above
**/
function getWidth(elem) {
Return parseInt(getStyle(elem, 'width'));
}
Code source: https://gist.github.com/hehongwei44/b524ff25991d99625eb2
The above are the commonly used JavaScript scripts shared in this article. I hope you all like them.

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 中国語版
中国語版、とても使いやすい

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ホットトピック



