[6][A.Thông điệp][slider-top-big][nothing]
You are here: Home / , , , , Code highlight(select all) blockquote hoặc thẻ pre

Code highlight(select all) blockquote hoặc thẻ pre

| 2 Comments
Mình đang tìm giải pháp copy to clipboard cho blockquote. Tuy vậy thì có lẽ code cho blogger hơi phức tạp ..
Giải pháp thay thế tạm thời là tạo select all code trong blockquote. Hướng dẫn này sẽ giúp bạn tạo select all một cách dễ dàng :

Demo tại hướng dẫn này :

Bước 1: Thêm thư viện js trước </head> (nếu bạn đã có rồi thì bỏ qua) :

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'/>

Bước 2: Thêm Jquery sau :

Bất cứ vị trí nào trong </head> hoặc <body> :




 <script type='text/javascript'>
jQuery(document).ready(function($) {
    jQuery( &#39;blockquote.tr_bq&#39; ).click( function() {
        var refNode = $( this )[0];
        if ( $.browser.msie ) {
            var range = document.body.createTextRange();
            range.moveToElementText( refNode );
            range.select();
        } else if ( $.browser.mozilla || $.browser.opera || $.browser.chrome) {
            var selection = window.getSelection();
            var range = document.createRange();
            range.selectNodeContents( refNode );
            selection.removeAllRanges();
            selection.addRange( range );
        } else if ( $.browser.safari ) {
            var selection = window.getSelection();
            selection.setBaseAndExtent( refNode, 0, refNode, 1 );
        }
    } );
} );
</script>

Bước 3 : Save lại Template

Highlight cho cho thẻ pre tương tự bằng cách thay pr bằng blockquote là được.

(Minh Anh - Erhay)

Cảm ơn bạn đã theo dõi bài viết. Vui lòng ghi lại nguồn Erhay khi bạn phát hành lại thông tin từ trang này.