想有一個詞櫃檯旁邊的網站字計數器的JavaScript函數調用
上輸入文本框得到它的工作,顯示計數,當用戶點擊或修改的文字,但我想加載直線距離時頁面完成加載。
$(document).ready(function() {
$("#product_name").change(displayText).keyup(displayText);
function displayText(){
$("em#counter").text($(this).val().length +' chars');
}
});
所以我試了下面的代碼,但不能得到它的工作原理,不知道爲什麼。
$(document).ready(function() {
if($("#product_name").length){
displayText();
}
$("#product_name").change(displayText).keyup(displayText);
function displayText(){
$("em#counter").text($(this).val().length +' chars');
}
});
非常感謝。
什麼不起作用/ – gdoron 2013-03-01 06:28:05
我們需要更多信息來回答您的問題。它拋出一個錯誤? – yourdeveloperfriend 2013-03-01 06:30:51