我有一个复选框和用于更新数据的复选框的单击事件。当我单击复选框时,数据正在更新,但复选框不会被选中。
这是我的 html 代码:
<td>
<input type="checkbox" data-bind="checked: status, disable: status, click: $root.UpdateStatus" />
</td>
这是我的脚本:
self.UpdateStatus = function (tblUsers) {
$.ajax({
type: "POST",
url: 'SinglePageApp.aspx/UpdateStatus',
data: "{statusVal: 'true',goalId: " + tblUsers.goalId + "}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
});
};
我希望我的复选框在被单击时被选中。然后在单击复选框后放置更新的数据。
See: http://knockoutjs.com/documentation/click-binding.html
注3:允许默认点击操作
默认情况下,Knockout 将阻止点击事件采取任何
默认操作。这意味着如果您在 a 上使用单击绑定
标签(链接),例如,浏览器只会调用您的处理程序
函数并且不会导航到链接的 href。这是一个有用的
默认是因为当你使用点击绑定时,通常是因为
您将链接用作操作视图的 UI 的一部分
模型,而不是作为另一个网页的常规超链接。
然而,如果您确实想让默认的单击操作继续,只需
从您的点击处理函数返回 true.
Edit: added example showing where to return
true
in the function. It has to be return from the actual function itself, not the Ajax
success
or
error
handler.
self.UpdateStatus = function (tblUsers) {
$.ajax({
type: "POST",
url: 'SinglePageApp.aspx/UpdateStatus',
data: "{statusVal: 'true',goalId: " + tblUsers.goalId + "}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
});
// Return true to allow default click action.
return true;
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)