admin

JS控制超链接a标签的文字长度,超过部分省略号表示。
<script> function limitAnchor(XelementName, Xle...
扫描右侧二维码阅读全文
16
2020/03

JS控制超链接a标签的文字长度,超过部分省略号表示。

<script>
    function limitAnchor(XelementName, Xlength) {
        var anchors = document.getElementsByName(XelementName);
        for (var i = 0; i < anchors.length; i++)
            if (anchors[i].innerHTML.length > Xlength)
                anchors[i].innerHTML = anchors[i].innerHTML.substring(0, Xlength)

+ "...";   
</script>

<a href="javascript:void(0)" name="anchor">哈哈哈哈哈哈哈哈哈哈</a>

<script>limitAnchor("anchor", 5)</script>
Last modification:March 16th, 2020 at 09:47 pm

Leave a Comment