gpt4 book ai didi

jquery - 在 Angular js中单击确认框取消时防止选中复选框?

转载 作者:行者123 更新时间:2023-12-01 04:00:26 25 4
gpt4 key购买 nike

我有一个复选框,单击时我会显示一个确认框。当在确认框中单击“确定”时,它会被选中。这很好。我想防止在确认框中单击“取消”时检查它?每次我在确认框中单击“取消”时都会检查它吗?

代码如下

<input ng-model="checkboxValue" ng-click="makeLive(row)" type="checkbox">

$scope.makeLive = function (row)
{
if ($window.confirm("Sure to make it live?Can't edit after making it live.") === true)
{
alert("id====" + row.entity.id);

} else
{
return false;
}
};

最佳答案

由于我们发现此代码现在正在重复...

...您需要将 ng-model 更改为属于 row 对象(无论是什么)的变量。这将防止冲突的复选框点击相互覆盖。

所以你的 HTML 现在变成:

<input ng-model="row.isLive" ng-click="makeLive(row)" type="checkbox">

然后将row.isLive值赋给$window.confirm()函数的返回值:

$scope.makeLive = function(row) {

row.isLive = $window.confirm(
"Sure to make it live? Can't edit after making it live."
);

if (row.isLive){
// do something (if you want to)
else{
// do something else (if you need to)
}
};

演示

CodePen: Using $window.confirm() to continue-to (or cancel-from) checking a checkbox

关于jquery - 在 Angular js中单击确认框取消时防止选中复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46196932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com