html: <tr>
<td class='td_noborber'>活动名称:<span class="mustInput">*</span></td>
<td colspan="3" class="textWidth">
<input id="activity_name" name="activity_name" type="text" maxlength="50" style="height:25px;width:152px;"
οnkeyup="javascript:setShowLength(this,50,'#nameLenth');" />
<span style="color:red;display: none;" id="nameLenth">(还可以输入50个字数)</span>
</td>
</tr>
JS:$('#activity_name').textbox({
inputEvents: $.extend({},$.fn.textbox.defaults.inputEvents,{
keyup:function(event){
setShowLength(this,50,'#nameLenth');
}
})
});
function setShowLength(obj, maxlength, id)
{
var rem = maxlength - obj.value.length;
if (rem < 0){
rem = 0;
}
$(id).html("(还可以输入" + rem + "字数)");
}
$("#activity_name").textbox('setValue',result.activity_name);
$('#nameLenth').html("(还可以输入" + (50-result.activity_name.length) + "字数)");