首页 » 收集 » 正文内容
扒自虎(基)绿(佬)林的艾特代码
寻梦xunm| 376| 收集
2年前
超过841天 温馨提示
本文最后更新于2022年06月01日,已超过841天没有更新,若内容或图片失效,请留言反馈。

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

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>
0 赞 or 打赏
喜欢就打赏一点
微信 支付宝
隐私
Q Q:1340326824
邮箱:vipshiyi@qq.com
QQ群:422720328

我的音乐

微博客-专为自己编写开发的源码