2013-10-20 24 views
0

隱藏它並替換它的內容後,我在跨度中出現一些問題。jQuery不會在範圍內褪色

這裏是我的html更換之前

<span id="replace_with_editor"> 
    <a id="edit_button" class="btn btn-success" href="thread.php">Post ny tråd</a> 
</span> 

這裏是我的jQuery代碼

replace_with_editor = $('#replace_with_editor'); 
    $('#edit_button').click(function(e) { 
     e.preventDefault(); 
     replace_with_editor.hide(); 
     replace_with_editor.html('<form role="form" method="post" action="process/submit_thread.php"><div class="form-group"><label for="Title">Tittel</label><input id="thread_title" name="thread_title" type="text" class="form-control" placeholder="Skriv en tittel for tråden."></div><div class="form-group"><label for="Svar">Tråd</label><textarea id="thread_editor" name="thread_content" rows="10" class="form-control"></textarea></div><input type="hidden" value="category_id" name="category_id"><input type="hidden" value="forum_id" name="forum_id"><button type="submit" class="btn btn-success">Post tråd</button></form>'); 
     replace_with_editor.fadeIn(2000); 
    }); 

出於某種原因,當我嘗試這個劇本,新的內容顯示出來,但淡入()犯規工作,它顯示出即時。

任何猜測我做錯了什麼?哦,因爲調試,jQuery沒有嵌套。 任何幫助,非常感謝。

回答

0

嘗試通過回調你的隱藏功能。

replace_with_editor = $('#replace_with_editor'); 
    $('#edit_button').click(function(e) { 
     e.preventDefault(); 
     replace_with_editor.hide(function(){ 
     replace_with_editor.html('<form role="form" method="post" action="process/submit_thread.php"><div class="form-group"><label for="Title">Tittel</label><input id="thread_title" name="thread_title" type="text" class="form-control" placeholder="Skriv en tittel for tråden."></div><div class="form-group"><label for="Svar">Tråd</label><textarea id="thread_editor" name="thread_content" rows="10" class="form-control"></textarea></div><input type="hidden" value="category_id" name="category_id"><input type="hidden" value="forum_id" name="forum_id"><button type="submit" class="btn btn-success">Post tråd</button></form>'); 
     replace_with_editor.fadeIn(2000); 
}); 
    }); 

我還加了一個jsfiddle來告訴你,如果你想得到什麼。 http://jsfiddle.net/JfGZM/

+0

工程就像一個魅力。謝謝! –

+0

好吧,我現在試着淡出它,現在我有同樣的問題。 看看這個 http://jsfiddle.net/Danbannan/sQmaf/ –