Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript将输入无线电的不同值发送到模式4_Javascript_Jquery - Fatal编程技术网

如何使用javascript将输入无线电的不同值发送到模式4

如何使用javascript将输入无线电的不同值发送到模式4,javascript,jquery,Javascript,Jquery,我有一个销售脚本,我的客户需要一个模式,在一个输入收音机内每个产品有4个价格。我试过几种方法,但我不明白如何将4种价格发送到每种产品线的modal内的无线电输入 每一行产品都是通过javascript添加的,如下所示: var addNewRow = function(id){ html = '<tr id="tr_'+i+'">'; html += '<td class="prod_c" width="50%"><input type="text"

我有一个销售脚本,我的客户需要一个模式,在一个输入收音机内每个产品有4个价格。我试过几种方法,但我不明白如何将4种价格发送到每种产品线的modal内的无线电输入

每一行产品都是通过javascript添加的,如下所示:

var addNewRow = function(id){
    html = '<tr id="tr_'+i+'">';
    html += '<td class="prod_c" width="50%"><input type="text" data-type="nombreProd" name="nombreProd[]" id="nombreProd_'+i+'" class="form-control autocomplete_txt" autocomplete="off"></td>';
    html += '<td width="10%"><input type="text" name="cantidad[]" id="cantidad_'+i+'" class="form-control changesNo cq totalCantidad" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>';
    html += '<td width="10%"><input type="text" name="venta[]" id="venta_'+i+'" class="form-control changesNo vventa" data-toggle="modal" data-target="#escoger" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" readonly="readonly"></td>';
    html += '<td width="25%"><input type="text" name="total[]" id="total_'+i+'" class="form-control totalLinePrice pisto" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" ></td>';
    html += '<td class="trash_td"><i class="fa fa-trash fa-delete" aria-hidden="true" data-id="'+i+'"></i></td>';
    html += '</tr>';

    if( typeof id !== "undefined"){
        $('#tr_'+id).after(html);
    }else{
        $('table').append(html);
    }

    $('#caseNo_'+i).focus();
    i++;

    return (i-1);
};
这是模态,但我不知道如何将数据发送到每个输入收音机:

<div id="escoger" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">

        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_0">1
        </label>
        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_1">2
        </label>
        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_2">3
        </label>
        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_3">4
        </label>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

如果我有误解,请原谅,但问题似乎只是您没有为每个单选按钮添加
属性。我在这里添加了一些示例;你可以运行它,看看这是否是你所缺少的

$('input')。在('click',函数(e){
警报($('#'+e.target.id).val());
});

&时代;
模态头
1.
2.
3.
4.
接近

也许这就是你要找的。做下面这样的事情

JAVASCRIPT

$('#escoger').on('shown.bs.modal', function () {

    var venta0 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.
    var venta1 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.
    var venta2 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.
    var venta3 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.

    var vt0     = $('input[name="venta"]:eq(0)',this); // Set target input with their own index (eq).
    var vt1     = $('input[name="venta"]:eq(1)',this); // Set target input with their own index (eq).
    var vt2     = $('input[name="venta"]:eq(2)',this); // Set target input with their own index (eq).
    var vt3     = $('input[name="venta"]:eq(3)',this); // Set target input with their own index (eq).

    vt0.val(venta0).prop('checked',true) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
    vt1.val(venta1) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
    vt2.val(venta2) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
    vt3.val(venta3) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
});

jsIDLE示例:

不,当我点击任何一个输入单选按钮时,该值不是DB中的值,这就是我的问题所在……这些值不会显示在每个输入中,就像每个示例中,如果项目胶水的信息为3.10、2.45、2.10和1.90,则这些值是我需要在每个单选按钮中显示的值,而不是1、2、3、4。然后,当我选择其中一个时,我需要javascript更改inputYes中的值,这就是我要找的!。但是我不知道为什么该值没有显示在模式中(测试值有效)。我认为这是因为加载页面时的输入不存在,并且因为该值为空。。。但是,如果我在val()中添加了一些内容,那么当我第一次打开模式()时,输入会更改为NaN或object(),每个收音机中的值都是空的,但是当我关闭模式,然后再次打开时,会显示值()。你知道为什么会发生这些吗?嗯。我不知道这是为什么。应该已经将其设置为该值。我没有你剩下的代码。所以我不能回答这个问题。在打开模式并设置值之前是否执行操作(代码)?是的,因为如果我不选择该项,则输入按钮不存在,如果该项存在,javascript将创建每一行输入。第一次使用演示值,但第二次使用“我的代码”…在您想要执行单击模式按钮的操作之前,使用您获得的表格/HTML结果更新您的问题。我需要知道这个val是从哪里来的
$('#venta_3'+id[1]).val();和其他人
以及id[1]
来自何处。
<div id="escoger" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">

        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_0">1
        </label>
        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_1">2
        </label>
        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_2">3
        </label>
        <label class="radio-inline mr10">
            <input type="radio" name="venta" id="venta_3">4
        </label>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
//price change

$(document).on('change keyup blur','.changesNo',function(){

// .changeNo are the class inside of ventas, cantidad(quantity) inputs

// in this part the ID came from

    id_arr = $(this).attr('id');  
    id = id_arr.split("_");

    cantidad = $('#cantidad_'+id[1]).val();
    existencia = $('#existencia_'+id[1]).val();
    venta = $('#venta_'+id[1]).val();
    venta1 = $('#venta1_'+id[1]).val();
    venta2 = $('#venta2_'+id[1]).val();
    venta3 = $('#venta3_'+id[1]).val();

    if( cantidad!='' && venta!='')

    calculateTotal();

});
$('#escoger').on('shown.bs.modal', function () {

    var venta0 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.
    var venta1 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.
    var venta2 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.
    var venta3 = Math.floor((Math.random() * 100)); // Test value (random). Change it back according to your code later.

    var vt0     = $('input[name="venta"]:eq(0)',this); // Set target input with their own index (eq).
    var vt1     = $('input[name="venta"]:eq(1)',this); // Set target input with their own index (eq).
    var vt2     = $('input[name="venta"]:eq(2)',this); // Set target input with their own index (eq).
    var vt3     = $('input[name="venta"]:eq(3)',this); // Set target input with their own index (eq).

    vt0.val(venta0).prop('checked',true) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
    vt1.val(venta1) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
    vt2.val(venta2) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
    vt3.val(venta3) // Set the value
    .closest("label").html(function(){ // Customize/Set again the html in label. Because this input inside the label and its text value
        return [$("input",this),$("input",this).val()]; // Return the input in this label with its text value back into html
    });
});