2013-10-29 66 views
0

我正在使用jquery插件(smartwizard)來製作表單嚮導。插件會自動在表單中出現的所有鏈接上添加一個名爲「isdone」的屬性和一個名爲「done」的類。這有助於插件瞭解哪些表單步驟已完成。但是由於增加了類,它會使表單中的其他鏈接發生故障。我想從某些鏈接中刪除類和屬性。如何在頁面加載後使用jquery刪除元素的屬性/類,如果該屬性是由另一個腳本添加的(Smartwizard插件)

我有此鏈接:

<a href="sample.com" id="file_link">My link</a> 

頁面加載後的插件添加以下屬性和階級

<a href="sample.com" class="done" isdone="1" id="file_link">My link</a> 

這裏是代碼片段初始化嚮導,我的嘗試:

jQuery(document).ready(function(){ 
jQuery('#wizard').smartWizard({ 
selected:1, 
enableAllSteps:false, 
transitionEffect:'slideleft', 
onLeaveStep:leaveAStepCallback, 
onFinish:onFinishCallback, 
onContinueLater:onContinueLaterCallback, 
enableFinishButton:false, 
}); 
// 
jQuery('#file_link').removeAttr('isdone');//doesn't work 
    jQuery('#file_link').live(function(){ 
    jQuery(this).removeAttr('isdone');//doesn't work also 
}); 
}); 

任何想法如何解決這個問題?

+0

@ C-Link。你的建議和Latheesan Kanes的建議如果在停用插件的情況下測試,我嘗試刪除任意屬性。但是會打破啓用的時刻。初始化嚮導後,我添加了代碼。因爲我的小知識告訴我,這些屬性是在插件完成它的執行後添加的。我不知道爲什麼這些代碼不能工作。任何更多的建議將不勝感激 –

回答

1

的代碼添加到文件準備好功能。

$(document).ready(function() 
{ 
    setTimeout(function() { 
     var myAttr = $('#file_link').attr('isdone'); 
     if (typeof myAttr !== 'undefined' && myAttr !== false) { 
      $('#file_link').removeAttr('isdone'); 
     } 
    }, 250); 
}); 
+0

他的代碼已經在文檔準備功能.... –

+0

我已經試過這個,並沒有工作,這是因爲你的建議和我的唯一區別是,你已經添加了一個檢查爲myAttr。 –

+0

可能是您的另一個文檔就緒腳本在您之後執行的問題。嘗試添加一個小的延遲。看到我更新的答案。 – Latheesan

0

試試這個:

jQuery('#file_link').on('load',function(){ 
jQuery(this).removeAttr('isdone'); 
}); 
相關問題