douya5331 2016-05-16 11:14
浏览 176
已采纳

如何使用jquery在文本框中设置多个值

I have a text box. When I click on the listed data (Data is getting from table). I need to set response table row ID in text box.

I need data to set like this "|13456|1400|14567|" in the text box. Please help me to set id in text box. Currently I can set only one ID. Please find the attached image

JS

$.post("getDetailsAjax.php", {keywords: keywords}, function(data){ 
    $.each(data, function() {
        var leftboxid = this.id;
        var producer = this.producer;
        var model = this.model;
        var typ = this.typ;
        var body = this.body;
        var date_from = this.date_from;
        var date_to = this.date_to;
        var power = this.power;
        var engine_code = this.engine_code;
        var fuel = this.fuel;
        var ccm = this.ccm;
        var cylinders = this.cylinders;
        $('#search-result').append('<div class="leftboxid_'+leftboxid+'" data-leftbox="' +leftboxid+ '"><a href="#" class="list-group-item"><p class="list-group-item-text">' +producer+ ' '+model+' '+typ+' ('+body+')</p><p class="list-group-item-text">' +date_from+ ' to ' +date_to+ '</p> <p class="list-group-item-text">' +power+'  ps .' +engine_code+' . ' +fuel+ ' . '+ccm+' ccm . ' +cylinders+ ' cyl</p></div>');
        /* right box */
        $(".leftboxid_"+leftboxid).on("click", function(){
            var setID = $(this).attr("data-leftbox");
            $(".append-left-id").attr("value", setID);
        });
    });
}, "json");

Textbox

<div class="col-xs-4">
    <input type="text" class="form-control append-left-id" placeholder="Result Field">
</div>
  • 写回答

2条回答 默认 最新

  • dongshengli6384 2016-05-16 11:24
    关注

    I think you want this

    instead of this code:

    $(".leftboxid_"+leftboxid).on("click", function(){
        var setID = $(this).attr("data-leftbox");
        $(".append-left-id").attr("value", setID);
    });
    

    use this :

    $(".leftboxid_"+leftboxid).on("click", function(){
        var setID = $(this).attr("data-leftbox");
        $(".append-left-id").val($(".append-left-id").val()+"|"+setID);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理