
this.name = name // 通过this来声明对象私有属性
}
Person.prototype.say = function () {
console.log("my name is ", this.name)
}
// Test
var person = new Person()
person.say()
JavaScript动态建立或增加CSS样式表,参考如下:
1、简单的方法:
document.createStyleSheet().cssText = '标签{color:red' +// 这个注释只在当前JS中帮助理解,并不会写入CSS中
'width:300pxheight:150px}' +
'.类名{……}' +
'#ID们{……}'
2、比较完美的方法,防止重复添加,通过添加样式表ID并对其判断来实现:
if (!document.styleSheets['要建立的样式表ID如theforever']) { //先检查要建立的样式表ID是否存在,防止重复添加var ss = document.createStyleSheet()
ss.owningElement.id = '要建立的样式表ID如theforever'
ss.cssText = '标签{display:inline-blockoverflow:hidden' +
// 这个注释只在当前JS中帮助理解,并不会写入CSS中
'text-align:leftwidth:300pxheight:150px}' +
'.类名{……}' +
'#ID们{……}'
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)