2010-07-23 69 views
0

我試圖從一個。點擊事件傳遞一個variabel的顏色框插件,像這樣使變量市民:從jQuery的。點擊

$('.w_price_assess p.price_report > a').live('click', function() { 

    var $reportRef = $(this).attr('href'); 

    var $reportID = $reportRef.substr($reportRef.lastIndexOf('/') + 1); 

    return false; 

}); 

我需要$reportID可見一個AJAX調用而形成的部分一個URL。

可以這樣做嗎?我做這方面的知識顯然是有限的:(

回答

2

如何聲明變量點擊事件外,並給予它的知名度公:

var $reportID = null; 

$('.w_price_assess p.price_report > a').live('click', function() { 

    var $reportRef = $(this).attr('href'); 

    $reportID = $reportRef.substr($reportRef.lastIndexOf('/') + 1); 

    return false; 

}); 

現在你可以在你的腳本中使用$reportID其他地方也

+0

這能用來傳遞到顏色框AJAX調用如上 – RyanP13 2010-07-23 10:21:42

+0

@Ry? anP13:是的,確保你在'

0

我試圖$ reportID傳遞給顏色框插件,像這樣:

// Colorbox dialog window for price report 
// Once dialog loaded append navigation header 
$('.w_price_assess p.price_report > a').colorbox({ 
    title: 'Price report', 
    transition: 'elastic', 
    innerWidth: '800px', 
    innerHeight: '650px', 
    opacity: '0.5', 
    onComplete: function() { 
     // Call the dialog header and append 
     $.ajax({ 
      type: 'GET', 
      url: DashboardApplicationRoot + 'PriceReport/' + $reportID + '/header', 
      dataType: 'html', 
      cache: false, 
      success: function(data) { 
       $('#cboxTitle').append(data); 
       // re-initialise form styling 
       //$('form.jqtransform').jqTransform();      
      }, 
      error: function(xhr, ajaxOptions, thrownError) { 
       alert(xhr.status); 
       alert(thrownError); 
      } 

     }); 

     // re-initialise scroll bars 
     $('#cboxLoadedContent').jScrollPane(); 

     $('#cboxLoadedContent table').removeAttr('width'); 

     $('.Section1').wrap('<div class="print_me" />'); 

     $('.Section1').css({ 
      'width': '95%', 
      'margin': 'auto' 
     }); 

     $('.Section1 table').css({ 
      'width': '100%', 
      'margin': 'auto' 
     }); 

     $('#cboxLoadedContent > div').addClass('dialog_loaded'); 

    }, 

    onClosed: function() { 

     // fixes scroll bar duplication bug 
     $('#cboxContent .jScrollPaneContainer').remove(); 

    } 

});