在嵌套函數外功能的元件I具有一個具有改變功能和Ajax內的各功能..訪問在jquery的
$(".spring_explorations").each(function() {
$("#" + this.id + " select").change(function() {
alert("t");
$.ajax({
type: 'POST',
url: ('/admin/applications/get_sections_for_modal'), //pass query string to server
data: {
exploration_id: $("#" + this.id + " select").val()
},
success: function (response) {
$(this).parents('span').next().show();
$(this).parents('span').next().find("select").html(response);
console.log(response);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(thrownError);
}
})
});
});
我想訪問success
片斷內spring_explorations
類的$(this)
元件ajax
腳本。
我能夠通過添加context: this
訪問change
函數的元素,但是如何獲取外部元素?
謝謝先進。
編輯:
的$(this).parents('span').next().show();
等是不確定的,因爲也許this
是AJAX本身不是spring_explorations
類。
如果這是一個重複的問題,我很抱歉。我只是相當新的JavaScript,我認爲這是正確的地方問這個問題。如果您認爲這不合適,請關閉我的問題。
這是許多問題的重複。 – Nit
@Nit - 哪一個是規範的? –