JQを使用してテキストの切り捨て関数を実行しましたが、JQを使用しないプロジェクトにこの関数を実装するには面倒です。 JSテキストの切り捨て関数は次のとおりです。コードを直接アップロードします。
HTML(テスト用):
<div>私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoです私はpoです私はpo>私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです>私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxですpox私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです。私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです私はpoxです
JS:
var limit = []; var text = []; var pox = document.getElementsByTagname( '*'); for(var i = 0; i <pox.length; i ++){if(pox [i] .getattribute( "limit")){limit [i] = pox [i] .getattribute( "limit");テキスト[i] = pox [i] .innerhtml; if(limit [i] <text [i] .length){pox [i] .innerhtml = text [i] .substring(0、limit [i])+"..."; }}}ここで、getElementsByTagnameを使用して、すべてのノードトラバーサルを取得します。 (pox [i] .getattribute( "lime"))を含むノードをフィルタリングする場合、各ノードのカスタム属性制限の値を取得し、それを制限配列に入れ、各ノードテキストをテキスト配列に入れ、テキストの長さにトランケートする必要がある値を比較し、トランケートします。
すべてのJS、ここに書かれたセルフチューニング:
<script type = "text/javascript"> window.onload = function(){(function limit(){var limit = []; var pox = document.getelementsbytagname( '*'); for(var i = 0; i <pox.length; i ++){if(pox [i] .getattribute(limit( "){" ") limit [i] = gettribute( "lime"); } </script>複製画像:
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。