1.インポート外部の.jsファイル:
1
|
<script src=
"js/jquery-1.8.3.js"
type=
"text/javascript"
></script>
|
2. <body>タグに次のコードを追加します。
1
2
3
4
5
6
7
8
9
10
11
12
|
<body>
还可以输入<span id=
"word"
>140</span>个字<br />
<textarea id=
"txt"
name=
""
cols=
""
rows=
""
></textarea>
<script language=
"javascript"
type=
"text/javascript"
>
$(
"#txt"
).keyup(function(){
if
($(
"#txt"
).val().length > 140){
$(
"#txt"
).val( $(
"#txt"
).val().substring(0,140) );
}
$(
"#word"
).text( 140 - $(
"#txt"
).val().length ) ;
});
</script>
</body>
|
3.ページでは、デフォルトのテキスト入力ボックス、ページのロードを実行するには、次のjQueryコードを、ロードされている場合にのみ正しく表示することができます:
1
|
$(
"#word"
).text( 140 - $(
"#txt"
).val().length ) ;
|