用一些新的var jquery替换var [英] Replace var with some new var jquery

查看:83
本文介绍了用一些新的var jquery替换var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码可以从数据库中查找某些内容,然后将其输出(如果存在). 现在,当我将其输出回来时,我需要单击这些输出之一,将其替换为其他变量中的var.

I have code to find something from database and output it back if it exists. Now when I output it back I need to make on click one of those outputs replace that output as var in some other var.

 $(document).ready(function() {
    $('#display').hide();
    $("#leavepost").keypress(function(event) {
        var key = (event.keyCode ? event.keyCode : event.which);
        if (key == 35) {
            $('#display').show();
            $('#leavepost').on('keyup', function() {
                var matches = $(this).val().match(/(^|\s)(#[a-z\d-]+)/ig)[0];
                var name = matches;
                $.ajax({
                    type: "POST",
                    url: "d/sul.php",
                    data: {
                        su: name
                    },
                    success: function(sss) {
                        $('#display').html(sss);
                        $(".adduser").click(function() {
                            var username = $(this).text();
                            var a = username;
                            var username2 = $(this).attr('id');
                            var E = "<a class='red' contenteditable='false' href='#' >" + a + "</a>";
                            var content = name.replace(name, E);
                            $("#leavepost").html(content);
                            $("#display").hide();
                            $("#leavepost").focus();
                        });
                    }
                });
            }).keyup();
        }
    });
});

当我单击class div隐藏时,但在此之前什么都没有发生...我需要从var name witdh var E中替换#word. 谢谢

When I click on class div hides but before that nothings happend... I need to replace #word from var name witdh var E. Thanks

推荐答案

您的问题很可能是因为您按照讨论中所述在<textarea>上使用了.html().

Your problem is most likely because you used .html() in on a <textarea> as stated in the discussion.

https://jsfiddle.net/q9gwdLj5/

$(function(){
  $("#choices li").click(function(){
    var name = $(this).text();
    $("#ta").val($("#ta").val().replace("#thisperson", name));
  })
})

.html()位更改为.val()将解决此问题.

Changing the .html() bit with .val() will fix the problem.

这篇关于用一些新的var jquery替换var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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