DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js代碼小記(判斷textbox的長度,並且固定最多收入字符)
js代碼小記(判斷textbox的長度,並且固定最多收入字符)
編輯:關於JavaScript     

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
<SCRIPT language=javascript1.3><!--
var testleng=300;//允許多少字符串填入

function GC_UpdateCharCount() {
  var desc_el = document.getElementById('desc');
  var remainingchars_el = document.getElementById('remainingchars');

  var num_remaining = testleng - desc_el.value.length;

  if (num_remaining >= 0) {
  remainingchars_el.innerHTML = num_remaining;
  } else {
  remainingchars_el.innerHTML = "<font color=red>" +
  (-num_remaining + '') + " characters over</font>";
  }
}
function isOver(sText)
            {
                var intlen=sText.value.length;
                if (intlen>testleng)
                {
                    alert("描述特征的內容的字數必修小於或者等於 "+testleng);
                    sText.focus();
                    sText.select();
                }
            }

//--></SCRIPT>
</head>

<body>
<<B>Group description</B><BR><TEXTAREA id=desc onkeydown=GC_UpdateCharCount() onkeyup=GC_UpdateCharCount()  onblur="isOver(this);"style="WIDTH: 99%" name=desc rows=4 cols=50></TEXTAREA>
            <BR>Letters remaining: <SPAN id=remainingchars>
            <SCRIPT language=javascript1.2><!--
              GC_UpdateCharCount();
              //--></SCRIPT></SPAN><NOSCRIPT>300 characters allowed </NOSCRIPT>
</body>
</html>

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved