简体   繁体   English

使用Twitter Bootstrap 3.0的手机无法显示模态

[英]Modals not displaying on mobiles using Twitter Bootstrap 3.0

I am putting together a website where I have a modal pop up with a web form contained in it when a button is clicked, it works completely fine on the desktop version of the website but wont do anything on a mobile or tablet. 我正在整理一个网站,当我单击一个按钮时,我会弹出一个模态弹出窗口,其中包含一个Web表单,它在网站的桌面版本上可以正常工作,但在手机或平板电脑上却无能为力。 Ive tested it on an iphone 5 and and ipad but dont get anything when I click the button, and even when I tested it on my desktop after resizing my browser to change to the tablet or mobile layouts it does not work either. 我已经在iphone 5和ipad上对其进行了测试,但是当我单击该按钮时却什么也没得到,即使在调整浏览器大小以更改为平板电脑或移动布局后在桌面上对其进行测试时,它也不起作用。 I'm using the most recent version of bootstrap and Im always using the most recent version of jquery for some other things but not that have anything to do with the modal so im not sure if that would affect it or not. 我正在使用最新版本的bootstrap,而Im总是在使用jquery的最新版本进行其他操作,但与模式无关,因此我不确定是否会影响它。 Here is the code I have currently 这是我目前拥有的代码

Here is the Modal with the Web Form inside of it. 这是其中包含Web表单的Modal。

<div class="modal fade" id="booknow" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
        <h2>Header</h2>
    </div>
    <div class="modal-body">
        <form class="form-horizontal" role="form">
        <div class="form-group">
        <label for="location" class="col-sm-4 control-label">Choose a Location</label>
        <div class="col-sm-8">
            <select id="firstSelect" class="form-control">
            <option value="0" selected="selected">None</option>
            <option value="dubai">Dubai</option>
                    <option value="bora">Bora Bora</option>
                    <option value="vancouver">Vancouver</option>
                    <option value="rio">Rio De Janeiro</option>
            </select>
        </div><br></br>
        <label for="resort" class="col-sm-4 control-label">Choose a Resort</label>
        <div class="col-sm-8">
            <select id="secondSelect" class="form-control">
            <option value="0" selected="selected">Choose Location First</option>
                <option class="location dubai">Resort 1</option>
                    <option class="location dubai">Resort 2</option>
                    <option class="location bora">Resort 3</option>
                    <option class="location bora">Resort 4</option>
                    <option class="location vancouver">Resort 5</option>
                    <option class="location rio">Resort 6</option>

            </select>
        </div><br></br>
        <label for="length" class="col-sm-4 control-label">Length of Stay</label>
        <div class="col-sm-8">
            <select class="form-control">
            <option>0 Days</option>
            <option>1 Day</option>
            <option>3 Days</option>
            <option>5 Days</option>
            <option>7 Days</option>
            <option>10 Days</option>
            </select>
        </div><br></br>
        <label for="airlines" class="col-sm-4 control-label">Available Airlines:</label>
        <br></br>
        <label for="name" class="col-sm-4 control-label">Name</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" placeholder="First and Last">
        </div><br></br>
        <label for="email" class="col-sm-4 control-label">Email</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" placeholder="email@example.com">
        </div><br></br>
        <label for="address" class="col-sm-4 control-label">Address</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" placeholder="Enter Address">
        </div><br></br>
        <label for="phone number" class="col-sm-4 control-label">Phone Number</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" placeholder="Enter Phone Number">
        </div>
        <a class="btn btn-default" data-dismiss="modal" id="submit">Submit</a>
        </div>
    </div>
    <div class="modal-footer">
        <a class="btn btn-default" data-dismiss="modal" id="close">Close</a>
    </div>
</div>
</div>
</div>

And here is the only CSS I have applied to it in my own stylesheet (this is only in the style sheet that affects the desktop version of the site, I dont have it included in the tablet or mobile versions of the stylesheet I have coded. 这是我在自己的样式表中应用到它的唯一CSS(这仅在影响网站桌面版本的样式表中使用,我没有在我编写的样式表的平板电脑或移动版本中包含它。

.modal-body {
height:400px;
}
.modal-footer > a {
margin-top:0px;
}

If you use data-toggle attribute then you should write your code like this and check your output using Chromes' developer tools: 如果您使用data-toggle属性,则应这样编写代码,并使用Chrome的开发人员工具检查输出:

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

Fiddle Demo 小提琴演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM