1、<span id="spanId">span的文本</span>的取值。
js取<span>的值并不是用document.getElementById('
spanId').value,而是document.getElementById('
spanId').innerText。
jquery取<span>的值,是$("#span_noticesg").html();
2、<span id="
spanId"></span>的赋值。
$('#
spanId').html("span的内容");
document.getElementById('
spanId').innerText="span的
内容";
3.js中字符串的拼接:
首先声明一个StringBuffer的方法:
function StringBuffer() { this.__strings__ = new Array(); } StringBuffer.prototype.append = function (str) { this.__strings__.push(str); return this; //方便链式操作 } StringBuffer.prototype.toString = function () { return this.__strings__.join(""); }
然后就可以像后台那样去拼接了:
var buffer = new StringBuffer(); buffer.append("Hello ").append("javascript"); var result = buffer.toString(); alert(result);