<script type="text/javascript">
//多行文本输入框剩余字数计算
function checkMaxInput(obj, maxLen) {
if (obj == null || obj == undefined || obj == "") {
return;
}
if (maxLen == null || maxLen == undefined || maxLen == "") {
maxLen = 100;
}
var strResult;
var $obj = $(obj);
var newid = $obj.attr("id") + ‘msg‘;
if (obj.value.length > maxLen) { //如果输入的字数超过了限制
obj.value = obj.value.substring(0, maxLen); //就去掉多余的字
strResult = ‘<div id="‘ + newid + ‘" class=\‘Max_msg\‘ ><span class=\‘red\‘>‘ + (maxLen -
obj.value.length) + ‘</span>/‘ + maxLen + ‘</div>‘; //计算并显示剩余字数
}
else {
strResult = ‘<div id="‘ + newid + ‘" class=\‘Max_msg\‘ ><span class=\‘red\‘>‘ + (maxLen -
obj.value.length) + ‘</span>/‘ + maxLen + ‘</div>‘; //计算并显示剩余字数
}
var $msg = $("#" + newid);
if ($msg.length == 0) {
$obj.after(strResult);
}
else {
$msg.html(strResult);
}
}
//清空剩除字数提醒信息
function resetMaxmsg() {
$("span.Max_msg").remove();
}
</script>
//使用
<textarea rows="5" cols="50" name="memo" id="mm" onkeydown="checkMaxInput(this,30)" onkeyup="checkMaxInput
(this,30)" onfocus="checkMaxInput(this,30)" onblur="checkMaxInput(this,30);"></textarea>
=================================================================================
//兼容浏览器,阻止默认 右键事件
$("#box").bind("contextmenu",function(event){