2013-06-04 2 views
1

Я использую скрипт для ограничения абзаца для нескольких слов только так для этого m, используя скрипт readmore .. но проблема в том, что он сворачивает абзац везде, где я нажимаю на текст, тогда как я хочу, чтобы он был разрушен когда Clicked on >> more link..so Я прошу кого-нибудь помочь мне в этом, что делать, чтобы он не принял щелчок по тексту.Подробнее Скрипт

    <!--readmore script--> 
       <script type="text/javascript"> 

       $(function() { 

        // Grab all the excerpt class 
        $('.excerpt').each(function() { 

         // Run formatWord function and specify the length of words display to viewer 
         $(this).html(formatWords($(this).html(), 15)); 

         // Hide the extra words 
         $(this).children('span').hide(); 

        // Apply click event to read more link 
        }).click(function() { 

         // Grab the hidden span and anchor 
         var more_text = $(this).children('span.more_text'); 
         var more_link = $(this).children('a.more_link'); 

         // Toggle visibility using hasClass 
         // I know you can use is(':visible') but it doesn't work in IE8 somehow... 
         if (more_text.hasClass('hide')) { 
          more_text.show(); 
          more_link.html(' &raquo; hide');   
          more_text.removeClass('hide'); 
         } else { 
          more_text.hide(); 
          more_link.html(' &laquo; more');    
          more_text.addClass('hide'); 
         } 

         return false; 

        }); 
       }); 

       // Accept a paragraph and return a formatted paragraph with additional html tags 
       function formatWords(sentence, show) { 

        // split all the words and store it in an array 
        var words = sentence.split(' '); 
        var new_sentence = ''; 

        // loop through each word 
        for (i = 0; i < words.length; i++) { 

         // process words that will visible to viewer 
         if (i <= show) { 
          new_sentence += words[i] + ' '; 

         // process the rest of the words 
         } else { 

          // add a span at start 
          if (i == (show + 1)) new_sentence += ' <span class="more_text hide">';  

          new_sentence += words[i] + ' '; 

          // close the span tag and add read more link in the very end 
          if (words[i+1] == null) new_sentence += '</span><a href="#" class="more_link"> &raquo; more</a>'; 
         }  
        } 

        return new_sentence; 

       } 
       </script> 
        <!--readmore script--> 


<body> 
<p class="excerpt">Lorem Ipsum is simply dummy text of the printing and typesetting  industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br><br> 


    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)....</p> 
</body> 
+0

Никто не будет смотреть через это. Попробуйте и сократите его, возможно, только начало функции. – Mattios550

ответ

2

А как насчет этих небольших шрифтов? DEMO http://jsfiddle.net/uEXvk/

HTML

<p class="excerpt">Lorem Ipsum is simply dummy text of the printing and typesetting  industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<br><br> 


    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like)....</p> 

CSS

a { 
    color: blue; 
    cursor: pointer; 
} 

Jquery

var orgContent = $('.excerpt').html(); 
    var txtContent = $('.excerpt').text().substr(0, 50) + '... <a id="morelink">more</a>'; 
    $('.excerpt').html(txtContent); 
    $("body").on("click", '#morelink', function(){ 
     $('.excerpt').html(orgContent); 
     $('<a id="lesslink"> less</a>').appendTo('.excerpt'); 
    }); 
    $("body").on("click", '#lesslink', function(){ 
     $('.excerpt').html(txtContent); 
    }); 
+0

Да, сэр отлично работает .. Спасибо за помощь сэр :) –

+1

Добро пожаловать, как насчет зеленого тика? ;) – yeyene

+0

oh yes ofcrse sir u заслуживает этого .. и PLS продолжают помогать мне sir thx a ton :) –

Смежные вопросы