gpt4 book ai didi

javascript - 单击按钮时,显示 Popover-Bootstrap 并选中复选框?

转载 作者:行者123 更新时间:2023-11-28 18:29:08 24 4
gpt4 key购买 nike

我使用 Popover Bootstrap 在用户单击“删除”按钮时向用户显示错误或警报。

  • 如果用户没有单击复选框并单击按钮 => 弹出窗口显示错误:“您应该选择一些记录!”
  • 如果用户单击复选框并单击按钮 => 弹出窗口显示警报:“您确定吗?”

我会调用ajax来删除这条记录。

我的代码为:

<script>

$(document).ready(function(){
if('#btn-delete').click(function(){
var isChecked = $('#ckbox').attr('checked') ? true : false;
if(isChecked==false)
{
$(this).popover({
title:'Alert',
content:'You should choose some records !',
html:true,
trigger:'focus'
return false;
})
else if(isChecked==true)
{
$(this).popover({
title:'Alert',
content:'Are you sure ?',
html:true,
// in here , i want to add button in popover like "Ok" , and then call AJAX
}
}
})
});


</script>

<html>
<body>
<div class="row">
<button type="button" id="btn-delete">Delete</button>

</div>
<table>
<thead>
<tr>
<th><input type="checkbox" id="checkall"/></th>
<th>ProductId</th>
<th>ProductName</th>
<th>ProductCat</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" id="ckbox"/></td>
<td>1</td>
<td>prod001</td>
<td>5</td>
</tr>
<tr>
<td>2</td>
<td>prod002</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>prod003</td>
<td>7</td>
</tr>
</tbody>

</table>

</body>
</html>

我怎样才能做到这一点?

最佳答案

<script>

$(document).ready(function(){
if('#btn-delete').click(function(){
var isChecked = $('#ckbox').attr('checked') ? true : false;
if(isChecked==false)
{
$(this).popover({
title:'Alert',
content:'You should choose some records !',
html:true,
trigger:'focus'
return false;
})
else if(isChecked==true)
{
$(this).popover({
title:'Alert',
content:'Are you sure ?',
html:true,
if (confirm('Are you sure you want to delete this?')) {
$.ajax({
url: 'myUrl',
type: "POST",
data: {
// data stuff here
},
success: function () {
// does some stuff here...
}
});
}
})
}
}

});


</script>

关于javascript - 单击按钮时,显示 Popover-Bootstrap 并选中复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38477936/

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