<script src="http://img.17k.com/js/jquery-latest.pack.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
jQuery.fn.numberLimit=function(){
var self = $("[@numberLimit]");
self.each(function(){
var objString = $(this).text();
var objLength = $(this).text().length;
var num = $(this).attr("limit");
if(objLength > num){
objString = $(this).text(objString.substring(0,num) + "...");
}
})
}
$(function(){
$("[@numberLimit]").numberLimit();
})
</script>
<div numberLimit="5">我太长了吗,怎么变成省略号了?</div>
<script language="javascript" type="text/javascript">
jQuery.fn.numberLimit=function(){
var self = $("[@numberLimit]");
self.each(function(){
var objString = $(this).text();
var objLength = $(this).text().length;
var num = $(this).attr("limit");
if(objLength > num){
objString = $(this).text(objString.substring(0,num) + "...");
}
})
}
$(function(){
$("[@numberLimit]").numberLimit();
})
</script>
<div numberLimit="5">我太长了吗,怎么变成省略号了?</div>