javascript克隆元素樣式的實(shí)現(xiàn)代碼
/**
* 克隆元素樣式
* @param {HTMLElement} 被克隆的元素
* @param {Boolean} 是否啟用緩存(默認(rèn)true)
* @return {String} css類(lèi)名
*/
var cloneStyle = (function (doc) {
var rstyle = /^(number|string)$/,
cloneName = '${cloneName}',
sData = {},
addHeadStyle = function (content) {
var style = sData[doc];
if (!style) {
style = sData[doc] = doc.createElement('style');
doc.getElementsByTagName('head')[0].appendChild(style);
};
style.styleSheet && (style.styleSheet.cssText += content) || style.appendChild(doc.createTextNode(content));
},
getStyle = 'getComputedStyle' in window ? function (elem, name) {
return getComputedStyle(elem, null)[name];
} : function (elem, name) {
return elem.currentStyle[name];
};
return function (source, cache) {
if (!cache && source[cloneName]) return source[cloneName];
var className, name,
cssText = [],
sStyle = source.style;
for (name in sStyle) {
val = getStyle(source, name);
if (val !== '' && rstyle.test(typeof val)) {
name = name.replace(/([A-Z])/g,"-$1").toLowerCase();
cssText.push(name);
cssText.push(':');
cssText.push(val);
cssText.push(';');
};
};
cssText = cssText.join('');
source[cloneName] = className = 'clone' + (new Date).getTime();
addHeadStyle('.' + className + '{' + cssText + '}');
return className;
};
}(document));
演示:
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(zhí)行]
相關(guān)文章
DB.ASP 用Javascript寫(xiě)ASP很靈活很好用很easy
DB.ASP 用Javascript寫(xiě)ASP很靈活很好用很easy,喜歡用js寫(xiě)asp的朋友可以參考下。2011-07-07JavaScript識(shí)別網(wǎng)頁(yè)關(guān)鍵字并進(jìn)行描紅的方法
這篇文章主要介紹了JavaScript識(shí)別網(wǎng)頁(yè)關(guān)鍵字并進(jìn)行描紅的方法,通過(guò)字符串的遍歷、匹配及動(dòng)態(tài)添加等操作實(shí)現(xiàn)識(shí)別與描紅的功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-11-11JavaScript在web自動(dòng)化測(cè)試中的作用示例詳解
這篇文章主要給大家介紹了關(guān)于JavaScript在web自動(dòng)化測(cè)試中的作用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08Bootstrap table 定制提示語(yǔ)的加載過(guò)程
bootstrap-table是在bootstrap-table的基礎(chǔ)上寫(xiě)出來(lái)的,專(zhuān)門(mén)用于顯示數(shù)據(jù)的表格插件。這篇文章主要介紹了Bootstrap table 定制提示語(yǔ),需要的朋友可以參考下2017-02-02JS禁用頁(yè)面上所有控件的實(shí)現(xiàn)方法(附demo源碼下載)
這篇文章主要介紹了JS禁用頁(yè)面上所有控件的方法,涉及JavaScript捕捉頁(yè)面元素的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2015-12-12window.location.href IE下跳轉(zhuǎn)失效的解決方法
這篇文章主要介紹了window.location.href IE下跳轉(zhuǎn)失效的解決方法,需要的朋友可以參考下2014-03-03BootstrapTable請(qǐng)求數(shù)據(jù)時(shí)設(shè)置超時(shí)(timeout)的方法
使用bootstrapTable獲取數(shù)據(jù)時(shí),有時(shí)由于網(wǎng)絡(luò)或者服務(wù)器的原因,無(wú)法及時(shí)獲取到數(shù)據(jù),頁(yè)面顯示一直處于等待狀態(tài)。為了改善效果,考慮設(shè)置超時(shí),請(qǐng)求發(fā)送后超時(shí)即顯示無(wú)數(shù)據(jù),過(guò)段時(shí)間重新發(fā)起請(qǐng)求2017-01-01layui點(diǎn)擊數(shù)據(jù)表格添加或刪除一行的例子
今天小編就為大家分享一篇layui點(diǎn)擊數(shù)據(jù)表格添加或刪除一行的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09