我正在尝试让JQueryUI从我从ajax请求返回的某些HTML中制作标签。我试图使用[$()。tabs()]的函数没有在我需要调用它的ajax.success函数中定义。
以下代码
function updateWidgets() {
for(x = 0; x < model.Widgets.length; x++){
Widget = model.Widgets[x];
var context = $(this);
return $.ajax({
url: Widget.AjaxUrl,
success: function (response) {
$('#' + Widget.StylingID).html(response);
$('.tabs').tabs();
}
})
}
};
HTML
<div class="tabs">
<ul>
<li><a href="#tabs-1">Server 1</a></li>
<li><a href="#tabs-2">Server 2</a></li>
<li><a href="#tabs-3">Server 2</a></li>
</ul>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, </p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat.</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. </p>
<p>Duis cursus. Maecenas ligula eros, blandit nec.</p>
</div>
</div>
答案 0 :(得分:0)
您的JavaScript应该是这样的:
$(document).ready(function(){
updateWidgets();
});
function updateWidgets() {
for(x = 0; x < model.Widgets.length; x++){
Widget = model.Widgets[x];
var context = $(this);
// no need to return as you might not using it as a promise object.
$.ajax({
url: Widget.AjaxUrl,
success: function (response) {
$('#' + Widget.StylingID).html(response);
$('.tabs').tabs();
}
})
}
}