Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script id="allScripts">
- $(document).ready(function() { // Execute when the DOM is fully loaded.
- // add a shortcut method/function
- (function( $ ) {
- // @search: a string used to as search and replace
- // @tag: tag to create wrapping element
- $.fn.wrapHanzi = function(search, tag, replace) {
- return this.each(function() {
- regex = new RegExp(search, 'g'); // create a regex on the fly, See: http://is.gd/BfR9gR
- @@ if (!replace) { replace = search; }
- wrap = '<'+tag+'>'+replace+'</'+tag+'>';
- $(this).replaceText( regex, wrap);
- });
- };
- })( jQuery );
- $("#text").wrapHanzi('水', 'easy');
- $("span").wrapHanzi('韓', 'unknow');
- $("span").wrapHanzi('國', 'partial');
- $("span").wrapHanzi('有', 'easy');
- @@ $("span").wrapHanzi('\\[', 'easy', '['); # 3 parameters
- $("span").wrapHanzi('\\]', 'easy', ']');
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment