2014-09-22 56 views
0

我正在处理一些有点令我困惑的jQuery代码。我仍然对jQuery不熟悉,并且我还没有尝试过使用它构建查询字符串(我更熟悉C#/ .NET)。将复选框值附加到使用JQuery查询字符串

我想要做的是将复选框的值附加到查询字符串,以便可以在另一个页面上使用它来进行电子邮件提交。如果复选框被选中,那么它的值应该被提交。如果复选框未选中,则不应提交任何内容。

注意:大部分代码不是我的,而是我必须处理的其他人的代码。

这里是jQuery代码(查询字符串参数我想设置为成员:要放什么东西在这里):

 if(success == 0) 
     { 
      if($('.catchTB').val().length == 0) 
      { 
       //CHECKBOX GROUPS 
       var personalInsurance = '', specialtyInsurance = '', commercialInsurance = ''; 
       $('.personalInsurance:checked').each(function() { 
        if(personalInsurance.length > 0) 
         personalInsurance = personalInsurance + ", "; 
        personalInsurance = personalInsurance + $(this).val(); 
       }); 
       $('.specialtyInsurance:checked').each(function() { 
        if(specialtyInsurance.length > 0) 
         specialtyInsurance = specialtyInsurance + ", "; 
        specialtyInsurance = specialtyInsurance + $(this).val(); 
       }); 
       $('.commercialInsurance:checked').each(function() { 
        if(commercialInsurance.length > 0) 
         commercialInsurance = commercialInsurance + ", "; 
        commercialInsurance = commercialInsurance + $(this).val(); 
       }); 

       //this is the code that sets up the parameters of the query string, and member is the one I want to set with the checkbox value 
       $.get("/UserControls/Forms/GetAQuoteProcessor.aspx", { fname: $('.firstName').val(), lname: $('.lastName').val(), email: $('.email').val(), telephone: $('.telephone').val(), address: $('.address1').val(), address2: $('.address2').val(), city: $('.city').val(), ddl: $('.ddl').val(), zipcode: $('.zipcode').val(), personalInsurance: personalInsurance, specialtyInsurance: specialtyInsurance, commercialInsurance: commercialInsurance, member: [what to put here], comment: $('.comment').val(), catchTB: $('.catchTB').val() }, 
        function(data){ 
       $('#getAQuote').css('display', 'none'); 
       $('.response').html(data); 
        }); 
      } 
     } 
    }); 

这是复选框:

 <td colspan="3" valign="top"><input type="checkbox" class="personalInsurance checkBox" id="member" value="Member of the NDGAA, PCSA, or Pet Professional Guild" /> Check if a you are a member of the NDGAA, PCSA, or Pet Professional Guild</td> 
+0

http://stackoverflow.com/questions/1090948/change-url-parameters/10997390#10997390 – technoTarek 2014-09-22 19:14:30

回答

0

要找到如果复选框被选中了,使用​​这样的:

var checked = jQuery('#member').is(':checked');

它将返回一个布尔值。

相关问题