相关疑难解决方法(0)

一旦出现,如何在Bootstrap模态中设置特定字段的焦点

我已经看过几个关于bootstrap模态的问题,但没有一个完全像这样,所以我会继续.

我有一个模态,我打电话就像这样......

$(".modal-link").click(function(event){
  $("#modal-content").modal('show');
});
Run Code Online (Sandbox Code Playgroud)

这工作正常,但是当我显示模态时我想要关注第一个输入元素...在可能的情况下,第一个输入元素的id为#photo_name.

所以我试过了

   $(".modal-link").click(function(event){
     $("#modal-content").modal('show');
     $("input#photo_name").focus();
   });
Run Code Online (Sandbox Code Playgroud)

但这无济于事.最后,我尝试绑定到'show'事件,但即便如此,输入也不会集中.最后只是为了测试,因为我怀疑这是关于js加载顺序,我放入一个setTimeout只是为了看看我是否延迟了一秒,焦点是否有效,是的,它有效!但这种方法显然是废话.有没有办法在不使用setTimeout的情况下获得与下面相同的效果?

  $("#modal-content").on('show', function(event){
    window.setTimeout(function(){
      $(event.currentTarget).find('input#photo_name').first().focus()
    }, 0500);
  });
Run Code Online (Sandbox Code Playgroud)

javascript modal-dialog twitter-bootstrap

182
推荐指数
6
解决办法
35万
查看次数

隐藏时的 Bootstrap 模式向 html 正文添加了填充权

我按以下顺序隐藏和显示模态:

当我点击导入按钮时,它将以模态为目标,id="import-actionpopup"然后我有另外两个按钮附加,并在我上传文件和选择选项时覆盖,然后这个import-actionpopup将被关闭,然后我有另外两个模态,id="warningOverrideAction"它们将在overrideButton上打开按钮单击和其他模态id="appendAction"将在appendButton单击时打开

现在,当我隐藏我的 warningOverrideAction 或 appendAction 模式时,它会自动添加 padding-right:17px; 到我的身体。

当我在 stackoverflow 上搜索时,我发现这是bootstrap.css 中的一个小故障,但我的问题是即使在模态隐藏后填充仍然存在

 $(document).ready(function(){

        $("#appendButton,#overrideButton").click(function(event){
            path=document.getElementById("zapper").value;
            if(path){       
             if($('#hinkSelect option:selected').prop('disabled') == true){
                   $('#reportError').modal('show');
                   document.getElementById('uploadError').innerHTML="<center>You have not selected any tool. <br>Make sure to select one tool.</center>";
                   document.getElementById('error_title').innerHTML="File Upload Error";
                  }
                  else{
                      toolName=document.getElementById('hinkSelect').value;
                      $('#import-actionpopup').modal('hide');
                      if(event.target.id==='overrideButton')
                      $('#warningOverrideAction').modal('show');
                      else if(event.target.id==='appendButton')
                      $('#appendAction').modal('show');
                      document.getElementById('hinkSelect').value='';
                  }
            }
            else{
                $('#reportError').modal('show');
                document.getElementById('uploadError').innerHTML="<center>You have not uploaded a zip file. <br>Make sure to upload …
Run Code Online (Sandbox Code Playgroud)

html css jquery bootstrap-modal

0
推荐指数
1
解决办法
3193
查看次数