想有一个词柜台旁边的网站字计数器的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