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 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥15 MATLAB数据处理插值
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的
  • ¥15 硬件IIC从模式的数据发送,中断数据的接收,不能用HAL库(按照时序图)