Javascriptle span veya bir div içerisinde karakter sınırlaması yapmak

Backendden gelen “lorem ipsum dolor” içeriğini html yüklenirken saydırıp karakter limiti 10’u geçiyorsa kesip sonuna elipsis “…” ekliyoruz.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script type="text/javascript">// <![CDATA[
$(document).ready(function() {
var substrText = function(text, max, endFix) {
var textLength = text.length,
endFix = endFix || "…";
if (textLength > max) {
return text.substr(0, max) + endFix;
}
}
var $box = $("#box"),
text = substrText("lorem ipsum dolor", 10);
$box.text(text);
});
// ]]></script>
PaylaşShare on Facebook0Share on Google+0Email this to someoneShare on LinkedIn0Tweet about this on TwitterPin on Pinterest0

için 4 cevap

  1. Ali BARIN diyor ki:

    Güzel bilgi fakat javaScript kodların yorumlanıp kaynak koda geçmişler, haberin olsun. Ellerine sağlık. :)

    • Punjaban diyor ki:

      Hi Neto. This is just a Jquery directory of pnluigs and tutorials. You might need to contact the plugin author through CodeCanyon.They have a great community that deals with those issues and I’m sure you can find help there.

  2. Evren Akar diyor ki:

    Eyvallah:) Blogla henüz uğraşamadım, yakın zamanda toparlayacağım içeriği.

    • Kwstas diyor ki:

      if you are entering all sletceed values of selectbox as comma seperated in mysql database, than you can retrieve that field. Explode it and check for each selectbox value with database value if value is in database array than make it sletceed.

Bir Cevap Yazın