2010-11-23 25 views
1

我正在使用ASP Classic腳本的舊系統上工作。如何使用JQuery使這個舊的JavaScript/ASP Classic代碼(乾淨)不顯眼?

在ASP經典文件我有渲染表的一部分的代碼段:

<td nowrap align="center"> 
    <%if iBidCount > 0 then %> 
    <a class="number-of-bids" onClick="showBidHistory(<% = oRSResults("ListedPlatesId") %>, this);" title="Click to show bid history"><%= iBidCount %></a> 
    <% else %><span class="no-bids">0</span> 
    <%end if%> 
</td> 

中的JavaScript我有onClick事件如下:

function fetchBidHistory (pListedPlatesId) { 
     var d = new Date(); 
     var t = d.getTime(); 

     $.get('/auction/includes/new-bidhistory.asp?lplateid=' + pListedPlatesId + "&xx=" + t, 
     function(data){ 
      $('#BidHistory').html(data).animate({opacity:1.0}, 400); 
     }); 
} 

function showBidHistory(pListedPlatesId, pObj) { 
    var lyrBidHistory = $('#BidHistory'); 
    //Populate the DIV 
    fetchBidHistory (pListedPlatesId);  
} 

,你可以看到我已經設法實現了一些JQuery。我的目標是儘可能使JavaScript不顯眼。另外我無法在DIV#BidHistory消失後出現問題嗎?

有沒有辦法做到這一點?有任何想法嗎?

任何幫助,非常感謝。謝謝

+0

不用擔心我解決了它! – Nasir 2010-11-23 16:32:35

回答

2

如果您希望JavaScript不顯眼,首先要從html中刪除事件處理程序,並將其替換爲JavaScript文件中的事件偵聽器。

例子:

<a class="number-of-bids" onClick="showBidHistory();">Old Link</a> 

變爲:

<a class="number-of-bids" id="bidHistoryLink">New Link</a> 

隨着你的JavaScript類似於一個額外的代碼行:

$('#bidHistoryLink').click(function() { 
alert('your bid history is:' bidHistory); 
}); 

這樣做可以讓你更加動態在你如何構建和重新組織網站。特別是通過網站進行更改變得更容易管理。