if (obj.toggle) {
var to = obj.toggle, ts = document.createElement('div');
ts.className = to.cssclass || 'toggle';
ts.innerHTML = obj.toggletext || '显示代码';
ts.onclick = new Function(
this.n + '.toggle(0, this);return false');
f.appendChild(ts)
}
edit.prototype.toggle = function(post, div) {
if (!this.d) {
var v = this.t.value;
if (div) {
div.innerHTML = this.obj.toggletext || '显示代码'
}
if (this.xhtml && !this.ie) {
v = v.replace(/<strong>(.*)<\/strong>/gi,
'<span style = "font-weight : bold;">$1</span>');
v = v.replace(/<em>(.*)<\/em>/gi,
'<span style = "font-weight : italic;">$1</span>')
}
this.e.body.innerHTML = v;
this.t.style.display = 'none';
this.i.style.display = 'block';
this.d = 1
}
}
问题:
if (div) 这句话 怎么理解啊。
var to = obj.toggle, ts = document.createElement('div');
ts.className = to.cssclass || 'toggle';
ts.innerHTML = obj.toggletext || '显示代码';
ts.onclick = new Function(
this.n + '.toggle(0, this);return false');
f.appendChild(ts)
}
edit.prototype.toggle = function(post, div) {
if (!this.d) {
var v = this.t.value;
if (div) {
div.innerHTML = this.obj.toggletext || '显示代码'
}
if (this.xhtml && !this.ie) {
v = v.replace(/<strong>(.*)<\/strong>/gi,
'<span style = "font-weight : bold;">$1</span>');
v = v.replace(/<em>(.*)<\/em>/gi,
'<span style = "font-weight : italic;">$1</span>')
}
this.e.body.innerHTML = v;
this.t.style.display = 'none';
this.i.style.display = 'block';
this.d = 1
}
}
问题:
if (div) 这句话 怎么理解啊。
第一种:true false
第二种:非0 0
第三种:非null null (容易混淆)
容易混淆的一个例子:
if(object){
}
表示如果有对象为真,无对象为假