简体   繁体   English

我想捕捉复选框被选中的参数

[英]I want to catch the argument whose checkbox is checked

I want to catch the argument whose checkbox is checked but if my tr is under form then he is giving me the whole tr.我想抓住复选框被选中的参数,但如果我的 tr 是在表单中,那么他给了我整个 tr。 Please help me.请帮我。 Here is my jQuery code:这是我的jQuery 代码:

 $('#form').on('submit',function(e){
    e.preventDefault();
    if($('.checkbox').is(':checked')){
            var selector = $(this).closest("tr")//get closest tr
            console.log(selector)
      //get select valus
        var id = selector.attr('data-id');
            alert(id);
        var package_name = selector.find('.visa_type').val();
        var prcs_type_price = selector.find("select[name=processing_type]").val();
        var processing_type = selector.find("select[name=processing_type] option:selected").text();
        var total = selector.find(".package_price").text(prcs_type_price).val()
            var date = selector.find('.travel_date').val();
    }
)};

Just run.each over the checked ones只需运行。每个检查过的

$('#form').on('submit', function(e) {
    e.preventDefault();
    $('.checkbox:checked',this).each(function() {
      const $row = $(this).closest("tr"); 
      const id = $row.id;
      const package_name = $row.find('.visa_type').val();
    })

You CAN do this .on("input" and have the fields update on any change您可以执行此.on("input"并在任何更改时更新字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM