酷秀  - kxiu.cn

扒自虎(基)绿(佬)林的艾特代码

admin的头像admin6个月前教程103热度

一个代码是扒自虎绿林中的艾特功能,其实简单的修改就可以实现其它快捷功能。

html快捷功能按钮事件绑定

<a href="#" onclick="atAdd('无名小卒',this);return false">@Ta</a>

js代码

<script>
            /* 将内容插入编辑框obj中光标所在的位置 */
            /* 感谢 @666 (uid: 16651) 编写了该函数 */
            /* https://hu60.net/q.php/bbs.topic.86665.html */
            function hu60_insert_text(obj, str) {  
                if (document.selection) {  
                    var sel = document.selection.createRange();  
                    sel.text = str;  
                } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {  
                    var startPos = obj.selectionStart,  
                        endPos = obj.selectionEnd,  
                        cursorPos = startPos,  
                        tmpStr = obj.value;  
                    obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);  
                    cursorPos += str.length;  
                    obj.selectionStart = obj.selectionEnd = cursorPos;  
                } else {  
                    obj.value += str;  
                }  
            }

            /* 将@标记插入光标位置,并使指定对象变色 */
            function atAdd(uid, that) {
                that.style.color = "#FFA500";
    //这里修改为相关表单显示的id
                var nr = document.getElementById("content");
                hu60_insert_text(nr, ' @'+uid+',');
            }
        </script>
签名: 最忠诚的BUG开发者来自: 重庆市. Chrome浏览器
文章目录

新年快乐

×
新年快乐
同喜