我創建了一個jQuery函數來計算文本字段中的字符數量並輸出數字。但它似乎並沒有被要求發佈密鑰。與文本字段的頁面是被納入index.php
外部頁面和js
被包括從外部js
文件。jQuery字符數 - 函數不被調用
$('#commentField').keyup(function() {
alert("functionCalled");
var max = 500;
var len = $(this).val().length;
if (len >= max) {
$('#charNum').html(' you have reached the limit');
} else {
var char = max - len;
$('#charNum').text(char + ' characters left');
}
});
文本區域:
<input type="text" name="commentArea" placeholder="Comment..." autofocus="autofocus" id="commentField"/>
的div
要填充:
<div id="charNum">here</div>
外部js
文件將被罰款的訪問,但功能似乎並沒有被調用。爲什麼這不起作用?
你沒有得到警報? – 2013-04-05 17:42:28
什麼是$(「#commentField」)。長度您添加KEYUP聽衆之前的價值? – 2013-04-05 17:42:47
不,我沒有得到警報。 – Colin747 2013-04-05 17:42:54