Javascript 如何停止现有微调器
我有以下Ajax请求,它位于从服务请求地址的部分视图中,可能需要几秒钟来填充表:Javascript 如何停止现有微调器,javascript,Javascript,我有以下Ajax请求,它位于从服务请求地址的部分视图中,可能需要几秒钟来填充表: @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "updatearea", OnBegin = "ShowLoading", OnComplete = "HideLoading" })) { <div id="updatearea" class="form-group"> <div style="widt
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "updatearea", OnBegin = "ShowLoading", OnComplete = "HideLoading" }))
{
<div id="updatearea" class="form-group">
<div style="width:300px; display:block; float:left;">
@Html.TextBox("PostCode", null, new { @class = "form-control" })
</div>
<div id="NewAddressLine">
<input id="btnLookupPostcode" type="submit" value="Lookup Postcode" class="btn btn-default" />
</div>
</div>
<div id="spinner"></div>
}
请让它停下来 可能是spinner.spin(false)或$('.spin').spin('hide');取决于使用的jQuery插件。你在用哪个图书馆?只是spin.js
您对小部件的引用也可能丢失。解决这一问题的多种方法;本质上,在您知道要维护的范围内创建一个变量,并将小部件分配给该变量以确保安全
var MySpinner = function(){
var spinner = undefined; //Widget will be assigned here
var opts = {
lines: 13, // The number of lines to draw
length: 20, // The length of each line
width: 10, // The line thickness
radius: 30, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '50%', // Top position relative to parent
left: '50%' // Left position relative to parent
};
return {
show: function(){
var target = document.getElementById('spinner');
spinner = new Spinner(opts).spin(target);
},
hide: function(){
spinner.stop();
}
}
}
var spinnerInstance = new MySpinner();
spinnerInstance.show();
spinnerInstance.hide();
最初是作为评论发布的,有点激进,但这将完全阻止它:
spinner.remove()
清除所有引用和附加事件…spinner.remove();-)假设引用是同一个实例,则Shows stop()应该可以工作。在
HideLoading()
中,您将spinner
重新定义为jQuery对象。大概.stop()
方法未绑定到此对象。在这些显示/隐藏方法之外定义spinner
。@Moob当我单击一个按钮时,部分视图正被注入到一个Div中,这意味着JS在打开部分之前无法看到与该部分相关的任何内容,如何在启动部分之前在显示/隐藏方法之外创建微调器,spinner div在partial中?@Shikkediel这是可行的,但这是正确的方法吗?
spinner.remove()