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>
http://stackoverflow.com/questions/1090948/change-url-parameters/10997390#10997390 – technoTarek 2014-09-22 19:14:30