我试图“警告”用户是否检查了表中的多行。如果长度不等于1,我会显示一个可以被解雇的警报。在用户解除警报之前,我不想继续使用其他模板。但是,它似乎是非阻塞的。
我已经查找了警报行为的描述,但是我没有看到阻塞与非阻塞的描述。
<div class="alert alert-warning alert-dismissible collapse" id="selectonlyone"
roll="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Warning!</strong> Select only one row to edit!
</div>
document.getElementById("btn3").onclick = function() {
var rowids = mytable.rows('.selected').data();
var pkids = [];
var arrayLength = rowids.length;
if(arrayLength==1){
...some code
}
else {
$('#selectonlyone').show();
document.location.href = "{% url 'show_template' %}" ;
}
};
不,他们不会阻止。根据Tim的建议,我使用了一个模态。模态也不会阻止。也就是说,“else”子句的执行将继续,但是模态将出现,用户将无法继续直到他们关闭模态。当他们关闭它时,用户仍然在原始页面。无论如何,用户可能更加注意模态。再次感谢蒂姆。
<div class="modal fade" tabindex="-1" id="myModal" role="dialog" data-backdrop="static" data-keyboard="false" aria-labelledby="exampleModalLabel" data-toggle="modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Warning!</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Select only one row to edit!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
document.getElementById("btn3").onclick = function() {
var rowids = mytable.rows('.selected').data();
var pkids = [];
var arrayLength = rowids.length;
if(arrayLength==1){
some code...
}
else {
$('#myModal').modal("show")
}
};