结合2个功能

时间:2011-03-17 13:29:20

标签: jquery

嘿所有, 在此先感谢帮助我解决这个问题。非常感谢您的任何建议。我会跳进去。

功能1

此功能从外部文件添加一组复选框。此功能可以多次进行,以便用户可以创建多个表单以同时提交

$( '#partners_internal_item_additem' ).click( function( e ){
        $( '#partners_program_registration' ).append(
            $( '<div>' ).load( 'accomodationpartners/programregistration1.html' )
        );
        e.preventDefault();
});

这就是它的回报:

<div class="partners_internal_item">
<div class="partners_internal_item_subhdrfull"><h2>Select a Product to Register For:</h2></div>
<div class="partners_internal_product_select">
    <fieldset><input type="checkbox" class="productselect" id="productselect_daytrip" /><label for="productselect_daytrip">Day Trip</label></fieldset>
    <fieldset><input type="checkbox" class="productselect" id="productselect_courseregistraion" /><label for="productselect_courseregistraion">Course Registration</label></fieldset>
    <fieldset><input type="checkbox" class="productselect" id="productselect_socialbusinessgroup" /><label for="productselect_socialbusinessgroup">Social/Business Group</label></fieldset>
    <fieldset><input type="checkbox" class="productselect" id="productselect_paddlefest" /><label for="productselect_paddlefest">Paddlefest</label></fieldset>
    <fieldset><input type="checkbox" class="productselect" id="productselect_paddleplay" /><label for="productselect_paddleplay">Paddle and Play</label></fieldset>
</div>
<div class="partners_internal_product_registration">hi</div>

功能2

此功能选中一个复选框并取消选择所有其他复选框。然后,此函数根据所选的复选框构建一个URL以加载到div中。

var checkboxes = $(':checkbox.productselect');
checkboxes.click(function() {
    /* uncheck checkboxes that aren't this one */
    $(checkboxes).not($(this)).attr('checked', false);
    /* get the name of the page to load
    from the id of the checkbox selected */
    var checkboxID = $(this).attr('id');
    var checkboxIDArray = checkboxID.split('_');
    var loadString = 'accomodationpartners/'+checkboxIDArray[1]+'.php';
    /* load the html into the div */
    $('.partners_internal_product_registration').load(loadString);
});

功能3

最近添加了这个函数来帮助包含前一个函数的结果。原因是函数#1可以多次发生,同一个类的HTML副本。然后,当用户完成功能#2时,它会影响所有其他功能,我似乎无法将功能#3无缝地集成到等式中。

 $('.partners_internal_product_select input[type=checkbox]').live('change', function(){
   // figure out which checkbox was checked and whatever
   // but only affect the registration that holds the checkbox:
   var AffectedRegistration = $(this).closest('.partners_internal_product_select');
   // this is where I try to incorporate function #2
});

1 个答案:

答案 0 :(得分:0)

您需要将ajax调用扩展为长格式,以便在回调中包含您的附加函数。在加载ajax内容后,回调会触发。这是关键。

$( '#partners_internal_item_additem' ).click( function( e ){
  $.ajax({
    url: "accomodationpartners/programregistration1.html",
    success: function(){
      function2();
      function3();
    }
  });
  e.preventDefault();
}