js span标签的取赋值以及字符串拼接

1、span的文本的取值。
 
js取的值并不是用document.getElementById(' spanId').value,而是document.getElementById(' spanId').innerText。

jquery取的值,是$("#span_noticesg").html();
 
2、spanId">的赋值。
$('# 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); 


你可能感兴趣的:(前端)