2014-03-28 41 views
0

由於某種原因,我的JavaScript代碼中的innerHTML正在鎖定其他JavaScript函數,而我也不知道爲什麼......這是鎖定其他人的JavaScript。JavaScript innerHTML鎖定其他javascripts

 var city = $('#search-bar').val(); 
     $.ajax({ 
      url: '/Index/getWeatherSearch', 
      data: { city: city }, 
      //async: false, 
      error: function (resp) { 
       alert("Error"); 
      }, 
      complete: function (resp) { 
       var div = document.getElementById('rb-grid'); 
       div.innerHTML = resp.responseText + div.innerHTML; 
      } 
     }); 
+3

'鎖'意味着什麼? – epascarello

+1

鎖定?你的意思是阻止其他jquery函數的一些錯誤? –

+1

可能重複:http://stackoverflow.com/questions/22694969/javascript-stop-working-after-ajax-call?rq=1 –

回答

3

不確定你的意思是鎖定正確,但你刪除元素並將其添加回來。最好追加新的內容。

var div = document.getElementById('rb-grid'); 
div.innerHTML = resp.responseText + div.innerHTML; 

$("#rb-grid").prepend(resp.responseText); 
3

如果你反正使用jQuery,爲什麼不使用jQuery?

使用success處理不是complete做:

$('#rb-grid').prepend(resp); 

的問題是,通過使用代碼innerHTML(AB),要重建該div元素整個DOM的一部分。您對所有後代DOM元素所做的所有事件處理程序和修改都將丟失。