请看清楚题目,是div本身的文本,不是div所包着的内容。
如下,我要获取id为text1所在的div所有的文本内容:
<div id="text1" style="left: 133px; top: 124px; width: 117px; height: 116px; z-index: 1;">这里填充的是text类型</div> 

解决方案 »

  1.   

    text()或者html()都是取这个div内部的东西,我是div自己本身自带的文本也要获取。
      

  2.   

    <div onclick="alert(this.outerHTML)">点击我:IE和chrome下可以这样</div><div onclick="alert(this.outerHTML)">点击我:纯JS通用解决方法</div>
    <script>
    if (typeof (HTMLElement) != "undefined" && !window.opera) {
        HTMLElement.prototype.__defineGetter__("outerHTML", function() {
            var a = this.attributes, str = "<" + this.tagName, i = 0;
            for (; i < a.length; i++)
                if (a[i].specified)
                    str += " " + a[i].name + '="' + a[i].value + '"';
            if (!this.canHaveChildren)
                return str + " />";
            return str + ">" + this.innerHTML + "</" + this.tagName + ">";
        });
        HTMLElement.prototype.__defineSetter__("outerHTML", function(s) {
            var r = this.ownerDocument.createRange();
            r.setStartBefore(this);
            var df = r.createContextualFragment(s);
            this.parentNode.replaceChild(df, this);
            return s;
        });
        HTMLElement.prototype
                .__defineGetter__(
                        "canHaveChildren",
                        function() {
                            return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/
                                    .test(this.tagName.toLowerCase());
                        });
    }
    </script>