我正在尝试让jquery loadmask插件工作以屏蔽元素(用于加载内容)。我正在使用 knockout.js,如果我在我的视图模型之外屏蔽一个元素,它会起作用,但我想在提交 POST 请求时屏蔽它,然后在收到它时取消屏蔽。我从这里得到一个“对象没有方法掩码”错误。我不太确定如何设置一个对象来访问它。
这行得通,但这不是我想要的。我在代码中注意到我想从中调用掩码
<div id = "register_container">
<div data-bind="visible: register()">
<div id = "register_form"> <!--this is the div I want to mask -->>
<button data-bind="click: submitRegistration">Submit</button>
</div>
</div>
</div>
function MyViewModel(){
self.submitRegistration = function(){
//I want to mask here. When I try it says Object[object object] has no method mask
$.post....{
if(data.result == success){
// andunmask here
}
}
}
}
$("#register_form").mask("Waiting..."); //the masking works when I place it here, but it's always enabled and I want it inside the viewmodel where I noted so it only works when the POST request is in process
这很好,但我想从我注意到的视图模型内部掩盖一些东西。我怎样才能做到这一点?