动态显示可输入的字数提示还可以输入的字数。
代码:
<input name="title" type="text" size="50" value="{$p.title}" maxlength="15" onkeyup="javascript:setShowLength(this, 15, ‘cost_tpl_title_length‘);"><span class="red" id="cost_tpl_title_length">还可以输入15字数</span>
js:
function setShowLength(obj, maxlength, id)
{
var rem = maxlength - obj.value.length;
var wid = id;
if (rem < 0){
rem = 0;
} // 脚本学堂 www.jbxue.com
document.getElementById(wid).innerHTML = "还可以输入" + rem + "字数";
}
{
var rem = maxlength - obj.value.length;
var wid = id;
if (rem < 0){
rem = 0;
} // 脚本学堂 www.jbxue.com
document.getElementById(wid).innerHTML = "还可以输入" + rem + "字数";
}