Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如果存在无效条目,如何避免关闭模式窗口?_Html_Twitter Bootstrap_Modal Dialog - Fatal编程技术网

Html 如果存在无效条目,如何避免关闭模式窗口?

Html 如果存在无效条目,如何避免关闭模式窗口?,html,twitter-bootstrap,modal-dialog,Html,Twitter Bootstrap,Modal Dialog,我正在使用twitter引导模式窗口。我使用jquery验证名称字段。当名称字段为空时,我在模式中显示错误。如果名称字段为空,我希望显示错误,并且模式窗口不应关闭 <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Close</a> <a href="#" class="btn btn-primary action_compute" data-dismiss="

我正在使用twitter引导模式窗口。我使用jquery验证名称字段。当名称字段为空时,我在模式中显示错误。如果名称字段为空,我希望显示错误,并且模式窗口不应关闭

<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<a href="#" class="btn btn-primary action_compute" data-dismiss="modal">Save changes</a>

$('.action_compute').click(function() {
  if($('#username').val() == ""){
    $(this).attr('data-dismiss', '');
    $('#show_error').show();
  }else {
    $(this).attr('data-dismiss', 'modal');
    $(this).parents('.modal').modal('hide');
  }
});

$('.action_compute')。单击(函数(){
如果($('#username').val()=“”){
$(this.attr('data-disease','');
$('show#u error').show();
}否则{
$(this.attr('data-disease','modal');
$(this).parents('.modal').modal('hide');
}
});

您可以尝试返回false以取消单击的默认行为(关闭模式),无需删除属性

$('.action_compute').click(function() {
    if($('#username').val() == ""){
        $('#show_error').show();
        return false;
    }
});

删除保存按钮中的数据以获得回复。如果我再次编辑并使字段为空,当我单击“保存”时,它会关闭模式窗口。我在这里遗漏了什么吗?@Mano你是说在我的小提琴中?它不应该在输入为空时关闭模式。你能详细说明一下你是如何测试的吗?