如何追加或环绕具体的标记文字 [英] How to append or wrap text around specific tag

查看:168
本文介绍了如何追加或环绕具体的标记文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在选择菜单中我有不同的BB codeS。我想知道我怎么可以包装/追加这样的[B] USER-HAS-类型化东西BB code标记中的 #message 用户输入[ / b]和最终结果为&LT输出; pre ID =显示>< / pre>

DEMO - http://jsfiddle.net/kwicher/ypmfK/2/


解决方案

  $(文件)。就绪(函数(){
    $('#enableuserreply')。点击(函数(){        VAR DIS = $(本).prop('检查')? :已禁用;        $(#用户名)丙(禁用,DIS)。
    });
    $('#enapletexteffect')。点击(函数(){        VAR DIS = $(本).prop('检查')? :已禁用;        $(#箱code)丙(禁用,DIS);
        $(#色)丙(禁用,DIS);
    });    $('#消息)。KEYUP(函数(){        如果($('#enableuserreply')是(':检查')){
            VAR味精= $(#用户名选项:选择)文本()+已输入。            VAR箱code = $(#箱code选项:选择),ATTR('值');            VAR消息= $('#消息)VAL()。
            味精味精= +消息;            VAR箱$ C $卡尔=新的Array();            如果(盒code){
                盒code = $ .trim(盒code.replace('[','<'));
                盒code = $ .trim(盒code.replace([/','< /'));
                盒code = $ .trim(盒code.replace(']','>'));
                盒code = $ .trim(盒code.replace(']','>'));
                盒$ C $卡尔=盒code.split('');
                 味精=盒$ C $卡尔[0] +味精+盒$ C $卡尔[1];
            }            $(#显示)HTML(MSG);
            VAR颜色= $(#颜色选项:选择),ATTR('值');            如果(彩色){
               $(#显示),CSS('色',颜色)。
            }
        }    });
});

这是完整的code。这是工作:)

In the select menu I have various bbcodes. I was wondering how I can wrap/append the user input from #message inside of a bbcode tag like this [b]USER-HAS-TYPED-SOMETHING[/b] and output that end results to <pre id="display"></pre>

DEMO - http://jsfiddle.net/kwicher/ypmfK/2/

解决方案

   $(document).ready(function() {
    $('#enableuserreply').click(function() {

        var dis = $(this).prop('checked') ? "" : "disabled";

        $("#usernames").prop('disabled', dis);
    });
    $('#enapletexteffect').click(function() {

        var dis = $(this).prop('checked') ? "" : "disabled";

        $("#boxcode").prop('disabled', dis);
        $("#colors").prop('disabled', dis);
    });

    $('#message').keyup(function(){   

        if ($('#enableuserreply').is(':checked')) {
            var msg = $("#usernames option:selected").text() + " has typed ";

            var boxcode = $("#boxcode option:selected").attr('value');

            var  message = $('#message').val();
            msg = msg + message ;

            var boxcodeArr = new Array();

            if(boxcode){
                boxcode = $.trim(boxcode.replace('[', '<'));
                boxcode = $.trim(boxcode.replace('[/', ',</'));
                boxcode = $.trim(boxcode.replace(']', '>'));
                boxcode = $.trim(boxcode.replace(']', '>'));
                boxcodeArr = boxcode.split(',');  
                 msg = boxcodeArr[0] + msg + boxcodeArr[1] ;         
            }

            $("#display").html(msg);  
            var color = $("#colors option:selected").attr('value');

            if(color) {
               $("#display").css('color', color);
            }


        }

    });
});

this is the complete code . it is working :)

这篇关于如何追加或环绕具体的标记文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆