日期:2014-05-17 浏览次数:20753 次
<!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> </head> <body> <script type="text/javascript"> $(function() { var dic = { '高兴': '忧伤', '悲伤': '喜悦', '凌乱': '冷静' }, test = '我真的感到很 [高兴] 啊!还很[悲伤] 啊! 我[凌乱]了 !' ; $.each(test.match(/[^\[]+(?=\])/g), function(i, word) { test = test.replace(word, dic[word]); }); $('body').append(test); }) </script> </body> </html>