首页 > 怎么取消img里的title属性的显示效果

怎么取消img里的title属性的显示效果

如题,因为我需要用title来传图片提示信息,提示框自己做,但不想显示原有的显示效果,怎么办,还有title最大支持多少字符


换属性+1


我有一个例子,最近工作中刚用过
js文件最好引用在最后,
html文档中放一个div元素,id='_altlayer'
代码非常丑陋,可以自己优化下

document.body.onmousemove = quickalt;
        document.body.onmouseover = getalt;
        document.body.onmouseout = restorealt;
        var tempalt = '';

        var UA = navigator.userAgent.toLowerCase();
        var ISIE = (UA.indexOf("msie") > 0);
        function getEle(hw_) {
            return document.getElementById(hw_);
        }

        function _Move(evn, o) {
            _bW = document.body.clientWidth;
            _left1 = document.body.scrollLeft + evn.clientX + 10;
            _oW = o.offsetWidth;
            _left = ((evn.clientX + _oW) > _bW) ? (_left1 - _oW - 10) : _left1;
            if ((evn.clientX + _oW) > _bW) {
                _left = (_oW < evn.clientX) ? (_left1 - _oW - 10) : _left1;
            }

            _bH = document.body.clientHeight;
            _top1 = document.body.scrollTop + evn.clientY + 6;
            _oH = o.offsetHeight;
            _top = ((evn.clientY + _oH) > _bH) ? (_top1 - _oH - 6) : _top1;
            if ((evn.clientY + _oH) > _bH) {
                _top1 = (_oH < evn.clientY) ? (_top1 - _oH - 6) : _top1;
            }
            o.style.left = _left;
            o.style.top = _top;
        }

        function getalt(hw_) {
            if (ISIE) {
                evn = event
            } else {
                evn = hw_
            }
            var eo = evn.srcElement ? evn.srcElement : evn.target;
            if (eo.title
                    && (eo.title != "" || (eo.title == "" && tempalt != ""))) {
                o = getEle("_altlayer");
                _Move(evn, o);
                o.style.display = '';
                tempalt = eo.title;

                eo.title = '';
                o.innerHTML = tempalt;

            }
        }
        function quickalt(hw_) {
            if (ISIE) {
                evn = event
            } else {
                evn = hw_
            }
            o = getEle("_altlayer");
            if (o.style.display == "") {
                _Move(evn, o);
            }
        }
        function restorealt(hw_) {
            if (ISIE) {
                evn = event
            } else {
                evn = hw_
            }
            var eo = evn.srcElement ? evn.srcElement : evn.target;
            eo.title = tempalt;
            tempalt = "";
            getEle("_altlayer").style.display = "none";
        }

可以使用 jQuery 的方法:

$("img").removeAttr('title');

IE 中 title 最大支持 512 个字符,来源 http://msdn.microsoft.com/en-us/library/ie/ms534683(v=vs.85).aspx

Titles are limited to 512 total characters; this limit includes control characters, such as line feeds, carriage returns, and so on.

【热门文章】
【热门文章】