關於js如果控制標簽的字符長度


js名字長度限定(如限制為50個字符,超過的顯示...)

var new_playerName = "";
        jQuery(".translate").each(function () {
            var s1 = jQuery(this).text().length;
            if (s1 > 50) {
                new_playerName = jQuery(this).text().substring(0, 50);
                    new_playerName += "..."
                    jQuery(this).html(new_playerName);
            } else {
                new_playerName = jQuery(this).text();
            }
            return new_playerName;
        })

循環獲取每個子集的字符長度,進行比較,如果大於50個字符 則進行截取,方法些許潦草,有更完善的方法還原交流討論。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM