首先查看示例:DEMO
復制代碼 代碼如下:
 
<form action="" method="post"> 
<h3><span>140</span>說說你正在做什么...</h3> 
<textarea rows="2" cols="40"></textarea> 
<p> 
<input type="image" src="images/btn.gif" /> 
<span></span> 
</p> 
</form> 
<div></div> 
<div> 
<div> 
<a href="#"><img src="images/user.gif"  /></a> 
<div> 
<p><strong><a href="#">Demo</a></strong>發布的內容...</p> 
<div></div> 
</div> 
<div></div> 
</div> 
</div> 
復制代碼 代碼如下:
 
h3{height:32px; line-height:32px; font-size:18px} 
h3 span{float:right; font-size:32px; font-family:Georgia,serif; color:#ccc; overflow:hidden} 
.input{width:594px; height:58px; margin:5px 0 10px 0; padding:4px 2px; 
border:1px solid #aaa; font-size:12px; line-height:18px; overflow:hidden} 
.sub_btn{float:right; width:94px; height:28px;} 
#msg{color:#f30} 
.clear{clear:both} 
.saylist{margin:8px auto; padding:4px 0; border-bottom:1px dotted #d3d3d3} 
.saylist img{float:left; width:50px; margin:4px} 
.saytxt{float:right; width:530px; overflow:hidden} 
.saytxt p{line-height:18px} 
.saytxt p strong{margin-right:6px} 
.date{color:#999} 
復制代碼 代碼如下:
 
<script type="text/javascript" src="../Script/jquery.js"></script> 
<script type="text/javascript" src="./Script/global.js"></script> 
復制代碼 代碼如下:
 
function recount(){ 
var maxlen=140; 
var current = maxlen-$('#saytxt').val().length; 
$('.counter').html(current); 
if(current<1 || current>maxlen){ 
$('.counter').css('color','#D40D12'); 
$('input.sub_btn').attr('disabled','disabled'); 
} 
else 
$('input.sub_btn').removeAttr('disabled'); 
if(current<10) 
$('.counter').css('color','#D40D12'); 
else if(current<20) 
$('.counter').css('color','#5C0002'); 
else 
$('.counter').css('color','#cccccc'); 
} 
復制代碼 代碼如下:
 
$(function(){ 
$('#saytxt').bind("blur focus keydown keypress keyup", function(){ 
recount(); 
}); 
$("#myform").submit(function(){ 
var saytxt = $("#saytxt").val(); 
if(saytxt==""){ 
$("#msg").show().html("你總得說點什么吧.").fadeOut(2000);; 
return false; 
} 
$('.counter').html('<img src="images/load.gif" />'); 
$.ajax({ 
type: "POST", 
url: "submit.php", 
data:"saytxt="+saytxt, 
dataType: "html", 
success: function(msg){ 
if(parseInt(msg)!=0){ 
$('#saywrap').prepend(msg); 
$('#saytxt').val(''); 
recount(); 
}else{ 
$("#msg").show().html("系統錯誤.").fadeOut(2000); 
return false 
} 
} 
}); 
return false; 
}); 
}); 
新聞熱點
疑難解答