【问题标题】:Bootstrap modal does not show up from code behindBootstrap 模态不会从后面的代码中显示出来
【发布时间】:2014-12-23 23:41:48
【问题描述】:

这应该很容易,但它不起作用。我在 Internet 上搜索并找到了一个示例并使用 Visual Studio 2013。div 仅在表单中,并且安装正确,并且表单中的引导项工作正常。

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

Page.ClientScript.RegisterStartupScript(Me.GetType(), "none", "$('#ModalZK');", True)


End Sub

div 类似于 bootstrap 示例,以

开头
<div class="modal fade" id="ModalZK" 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"><span aria-hidden="true">&times;</span><span class="sr-only"></span></button>
        <h4 class="modal-title" id="myModalLabel4" style="text-align:center ">Title</h4>
      </div>
      <div class="modal-body">

【问题讨论】:

    标签: asp.net vb.net twitter-bootstrap code-behind


    【解决方案1】:

    $('#ModalZK'); 不会做任何事情。打开模态:

    $('#ModalZK').modal('show');
    

    请参阅their documentation 了解更多详情。如果对 JavaScript 正在做什么有疑问,请先在浏览器的控制台中运行它。如果你在 Chrome 中运行你的代码,你会看到一些 HTML,表明它找到了该元素,但它不会做任何事情,因为你没有调用任何函数。

    工作示例:

    $('.ShowBtn').click(function() {
      $('#ModalZK').modal('show');
    });
    <script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
    
    
    
    <button type="button" class="ShowBtn">Show modal</button>
    
    <div class="modal fade" id="ModalZK" 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"><span aria-hidden="true">&times;</span><span class="sr-only"></span>
            </button>
            <h4 class="modal-title" id="myModalLabel4" style="text-align:center ">Title</h4>
          </div>
          <div class="modal-body">

    【讨论】:

    • VB 中的那一行说脚本必须是一个字符串,所以我用模态使它像这样并显示: Page.ClientScript.RegisterStartupScript(Me.GetType(), "none", "$ ('#ModalZK').modal('show');") 但后面的代码仍然没有弹出。 RegisterStartupScript 是否正确?
    • 哦,我只是认为我安装了(仅)Jquery 的 Javascript,也许这是一个问题?
    • @Henk 是的,这是个问题,你也需要参考 Bootstrap 的 JavaScript 库。在答案中查看我的代码 sn-p。
    • Firefox 中的 NoScript 警告不要这样做。我的 js 在 Form 之后和 Body 结束之前是/曾经是:
    • @Henk 它警告你不要做什么?你需要具体。您是否收到任何客户端 JavaScript 错误?您是否正确加载了所有文件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 2014-09-30
    • 2022-06-23
    • 2015-08-25
    • 2011-09-18
    相关资源
    最近更新 更多