作为前端很差的我,什么都要好好学习

<div class="reason_cancel"> <span>其它说明:(还可输入<font id="chLeft_remark">150</font>个字)</span>
          <textarea maxlength="150" onfocus="this.placeholder=''"  onblur="this.placeholder='| 请输入...'"  placeholder="| 请输入..." onkeyup="checkLength(this,'1');"  style="font-size:12px;" id="cancel_decsription"></textarea>
        </div>

前端js:

//字数限制
function checkLength(which,num) {
    if(num=="1"){
        document.getElementById("chLeft_remark").innerHTML = wordRestrict(which,150).toString();
    }
}

 

function wordRestrict(which,maxChars){
    var curr;
    if (which.value.length > maxChars)
    which.value = which.value.substring(0,maxChars);
    curr = maxChars - which.value.length;
    return curr;
}

posted on 2017-02-28 15:22  爱上码  阅读(632)  评论(0编辑  收藏  举报