我有四個菜單選項卡。在一個選項卡中是提交表單(默認),第二個選項卡包含條目列表,每個條目都有一個稱爲更改狀態的按鈕。當我點擊「更改狀態」時,我使用ajax調用windows.reload來刷新頁面,但該選項卡將返回默認的第一個。現在我的問題是我怎麼能更新menutab類到當前選定的菜單成爲一個活躍的。下面是我的阿賈克斯代碼:Ajax更改按鈕提交時鏈接的類名稱
<input type="button" value="change status"> // a button to click to change status
<a class="active">tab1</a> // need to change classname when the button clicked
<a class="nonactive">tab2</a> // need to change classname when the button clicked
<script>
$(document).ready(function() {
$(".closeBTN").click(function() {
var data = $(this).attr('id');
//alert (data);
$.ajax({
type: "POST",
url: "../deals_status_update.php",
data: { 'id': data }
}).done(function(msg) {
$("#notification").html(msg);
window.setTimeout(function(){
location.reload()
$('#itrade .active').removeClass().addClass('nonactive');
$('#iopendeals .nonactive').removeClass().addClass('active');
},100)
});
});
});
</script>
不是'location.reload()'與實際刷新相同嗎?如果是這樣,那麼你只是想捕獲你從ajax調用中得到的任何東西,然後操縱你的DOM結構來顯示你想要的頁面。 - 編輯:'location.reload()'確實刷新整個頁面就像F5一樣:https://developer.mozilla.org/en-US/docs/Web/API/Location.reload – Viridis