XtGem Forum catalog
Share JavaScript BBCode Toolbar | HTML - CSS - JS | Thảo luận Wap/Web - DDVP.MOBIE.IN
Trang ChủWap/WebXtgem ClubMediaTruyện Hay
Đăng NhậpĐăng Kí
HomeThảo luận Wap/WebHTML - CSS - JS
Tìm Kiếm | - 1 *Login to reply
▼ Share JavaScript BBCode Toolbar
* Admin
• Cấp Bậc: admin
12-12-2016
BBCode Toolbar dùng để nhập nhanh bbCode cho textarea, sử dụng tốt cho các diễn đàn hoặc blog. Code sử dụng tốt trên các trình duyệt cảm ứng hoặc web.

Bước 1: chèn javascript sau vào trước form:
<script type="text/javascript">
  function tag(text1,text2){
    if((document.selection)){
      document.form.msg.focus();
      document.form.document.selection.createRange().text = text1+document.form.document.selection.createRange().text+text2
    }else if(document.forms['form'].elements['msg'].selectionStart!=undefined){
      var element=document.forms['form'].elements['msg'];
      var str=element.value;
      var start=element.selectionStart;
      var length=element.selectionEnd-element.selectionStart;
      element.value=str.substr(0,start)+text1+str.substr(start,length)+text2+str.substr(start+length)
    }else{
      document.form.msg.value+=text1+text2
    }
  };
  function show_hide(a){
    b=document.getElementById(a);
    if(b.style.display=="none"){
      b.style.display="block"
    }else{
      b.style.display="none"
    }
  }
</script>
Copy code


Bước 2:
- Trong thẻ form thêm thuộc tính name="form"
- Trong thẻ textarea, nếu thuộc tính name khác "msg" thì tìm trong đoạn JavaScript trên chỗ nào có msg thì thay hết thành name của textarea.

Cách sử dụng:
- Để thêm một nút bấm, chỉ cần thêm code theo mẫu sau:
<a href="javascript:tag('', '')">In đậm</a>
Copy code

- Thay [ b ] và thành thẻ bbCode theo ý muốn

Chúc các bạn thành công!
▲ Tổng số: 1
- BBCode:

- Link:
CHÚ ÝNội quy forum