无聊,做了一个仿discuz论坛回帖添加表情效果.兼容ff,ie,chrome
以下是代码:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Comment Smilies</title> <script type="text/javascript" src="../js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $(".smile").hover( function() { $(this).css("cursor", "pointer"); }, function() { $(this).css("cursor", "default"); } ); $(".smile").click(function() { // Build the smile code. var smile = "[:" + $(this).attr("alt") + ":]"; var comment = $("#comment")[0]; // Insert the smile code into the current position. if ($.browser.msie) { comment.focus(); document.selection.createRange().text = smile; } else { // Get the pointer and current value. var start = comment.selectionStart; var end = comment.selectionEnd; var value = comment.value; // Insert the smile code. comment.value = value.substring(0, start) + smile + value.substring(end); // Restore the pointer location. comment.selectionStart = start + smile.length; comment.selectionEnd = start + smile.length; } }); }); </script> </head> <body> <textarea id="comment" cols="60" rows="6"></textarea> <img src="images/sweat.gif" alt="sweat" title="笑脸" class="smile" /> </body> </html>
原来Firefox不支持cursor:hand样式,害得我调试了半天,还以为是hover的问题呢!
转载声明: 出自: Ghoul To World!作者: GreatGhoul
This comment has been removed by the author.
ReplyDelete