我有一個常見的js文件 我重新加載ajax請求中的html頁面後,我不能訪問這個文件中的函數,常見的JS函數$(文件)。就緒(函數() 怎樣才能訪問這些和火在共同文件中的函數 例:
COMMON JS:
$(document).ready(function() {
$(".agree_btn").click(function(){
alert(123);
});
});
功能在PHTML頁
$('.loadMoreAnswers').live('click', function(event) {
var location_id = $(this).attr('location_id');
var counter= $(this).attr('counter');
$('#loadingAnswer').show();
$.ajax({
type: 'POST',
url: '/daleel/loadmore',
data: 'location_id='+location_id+'&part='+'answers'+'&answerCounter='+counter, //with the page number as a parameter
success: function(msg){
if(msg.length!=0) //if no errors
{ $(this).parent().load("view")
$('#loadingAnswer').remove();
counter+=5;
$('#profile-page-answer').append(msg);
}
else $("#loadingAnswer").remove();
},
dataType: 'html'
});
});
其呈現類似這樣的HTML:
<a agreed="no" agreed-content-id="63066" class="agree_btn" id="agree-a63066">
Agree
</a>
但是,當我在這個鏈接 點擊它並不在公共JS文件運行功能
在哪裏把.success(fucntion()){} – KJA
@KJA sry爲混亂成功處理已經在你的ajax調用中添加我已經編輯了答案 – Rafay
它不與通用js中的函數綁定。或者我不明白它好 – KJA