LOLWesta, a social media forum


You are not connected. Please login or register

View previous topic View next topic Go down Message [Page 1 of 1]

LOLWesta


LOLWesta King
Langsung aja ya...

Difficulty:Easy

Jadi,kita harus membuat div terlebih dahulu:

Code:
<div>
Halo,halo,ini text yang di-highlight.Halo!!
</div>
ATAU,jika di forum:

Code:
$(document).ready(function() {
$('#div.post').closest(post) function() {
});
Dan,buat kode ini:

Code:
 function getSelectionText() {
        var text = "";
        if (window.getSelection) {
            text = window.getSelection().toString();
        } else if (document.selection && document.selection.type != "Control") {
            text = document.selection.createRange().text;
        }
        return text;
    }
    $(document).ready(function (){
      $('div').mouseup(function (e){
          alert(getSelectionText())
      })
    });
Bagi yang nanya untuk apa code di atas, code di atas bekerja seperti :

"Search keyword : Halo"
Dan Javascript di atas akan langsung meng-highlight text div & akan menampakkan text div Wink
Kalau di PHP, code ini harus ditulis seperti ini :


Code:
$text = "halo selamat datang di LOLWesta, berikut adalah panduan - panduan forum";
$keyword = "forum, LOL, Westa, panduan";
$text = preg_replace("/($keyword)/i","<b>$1</b>",$text);

View user profile http://lolwesta.forummotions.com

View previous topic View next topic Back to top Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum