jQueryで長文部分表示を実装 code_jquery
May 16, 2016 pm 05:33 PM
jquery
Web ページには小さな領域しかありませんが、説明テキストが非常に長くなります。次のスクリプトは、長いテキストの部分表示を実装します。
ユーザーがクリックして展開するとテキストが展開され、閉じるとテキストが閉じます。
本来は jQuery の組み込み toggle() を使用して記述できましたが、実際に実行すると toggle が機能しなかったので、クリック フラグを使用して実行しました
コードをコピー コードは次のとおりです:
<スクリプト言語="javascript" src="jquery.js"></script>
<スクリプト言語="javascript">
var cur_status = "less" ;
$.extend({
show_more_init:function(){
//alert("show_more_init!");
var charNumbers=$(".content").html().length ;//総単語数
var limit=100;//表示単語数
if(charNumbers>limit)
{
var orgText=$(".content").html(); // 元のテキスト
var orgHeight=$(".content").height();// 元の高さ
var showText=orgText.substring(0,limit);// 最終的に表示されるテキスト
$ ( ".content").html(showText);
var contentHeight=$(".content").height();//コンテンツをインターセプトした後の高さ
$(".switch").click (
function() {
if(cur_status == "less"){
$(".content").height(contentHeight).html(orgText).animate({ height:orgHeight}, { 期間 : "遅い" });
$(this).html("収集");
cur_status = "詳細";
$(".content")。 height (orgHeight).html(showText).animate({ height:contentHeight}, {duration: "fast" });
$(this).html("expand");
cur_status = "less" ;
}
}
);
else
{
$(".switch").hide(); 🎜 >});
$(document).ready(function(){
$.show_more_init();
});
</script> ;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ; タイトル>テスト</タイトル>
#limittext{
位置:相対; ccc ;
カラー:黒;
.switch{
フォントサイズ:12px;
フォントファミリー; : バーダナ;
フォントの重さ: 800;
下: 0;
/*背景:url(more-bg.png) - x ボトム;*/
高さ:40px;
行の高さ:80px;
</style>
</head>
<body>
<div id="limittext" >
<div class="content" style=" padding-bottom:15px;">
This is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph Text, this is a long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, This is a long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is It’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph A paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph Text, this is a long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, This is a long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is It’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph A paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph Text, this is a long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, This is a long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is It’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph A paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph Text, this is a long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, This is a long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is a very long paragraph, this is It’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph, it’s a long paragraph A paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text, this is a very long paragraph Text, this is a long paragraph of text, this is a very long paragraph of text, this is a very long paragraph of text
</div>
<div class="switch">Expand</ div>
</div>
</body>
</html>
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

人気の記事
レポ:チームメイトを復活させる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
スプリットフィクションを打ち負かすのにどれくらい時間がかかりますか?
3週間前
By DDD
ハローキティアイランドアドベンチャー:巨大な種を手に入れる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)
1週間前
By 尊渡假赌尊渡假赌尊渡假赌

人気の記事
レポ:チームメイトを復活させる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
スプリットフィクションを打ち負かすのにどれくらい時間がかかりますか?
3週間前
By DDD
ハローキティアイランドアドベンチャー:巨大な種を手に入れる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)
1週間前
By 尊渡假赌尊渡假赌尊渡假赌

ホットな記事タグ

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック
Gmailメールのログイン入り口はどこですか?
7287
9


Java チュートリアル
1622
14


CakePHP チュートリアル
1342
46


Laravel チュートリアル
1259
25


PHP チュートリアル
1206
29



jQueryでPUTリクエストメソッドを使用するにはどうすればよいですか?

jQuery のヒント: ページ上のすべての a タグのテキストをすばやく変更する

jQuery を使用してすべての a タグのテキスト コンテンツを変更する

jQuery 要素に特定の属性があるかどうかを確認するにはどうすればよいですか?
