【问题标题】:Bootstrap modals won't launch引导模式不会启动
【发布时间】:2019-10-10 03:47:30
【问题描述】:

模态框不显示我的任何图像。我尝试更改图片和代码。但是我对此很陌生,我不知道。可能是javascript还是代码本身?我已经尝试过 atom 和 Dreamweaver,但我遇到了同样的问题。

$(function() {
    $('#site-modal').on('show.bs.modal',function() {
        $(this) 
               .find('.modal content img')
               .attr('src',$(event.relatedTarget).data('highres') )
    });                                     
});

圆顶排序的图片链接损坏。

$(function() {

  $('#site-modal').on('show.bs.modal', function() {
    $(this)
      .find('.modal content img')
      .attr('src', $(event.relatedTarget).data('highres'))
  });
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<!doctype html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <!-- css style sheet-->

  <!-- Bootstrap CSS -->
  <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
  <link href="css/bootstrap-4.2.1.css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link href="larry 2.css" rel="stylesheet" type="text/css">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Hello, world!</title>
</head>

<body>


  <header id="page-hero" class="site-header">
    <nav class="navbar navbar-expand-md navbar-dark">

      <div class="container-fluid">
        <a class="navbar-brand" href="#page-hero">
          <i class="fas fa-ankh"></i> LarryJ Designs</a>
      </div>

      <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#myTogglerNav" aria-controls="#myTogglerNav" aria-label="Toggle Navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

      <section class="collapse navbar-collapse align" id="myTogglerNav">
        <div class="navbar-nav">
          <a class="nav-item nav-link" href="index.html">Home</a>
          <a class="nav-item nav-link" href="about3.html">About </a>
          <a class="nav-item nav-link" href="portfolio2.html">Portfolio</a>
          <a class="nav-item nav-link" href="">Contact</a>
        </div>


      </section>


    </nav>


    <section class="layout-hero d-flex align-items-center text-light text-center">
      <div class="container">
        <div class="row justify-content-center">
          <div class="col-11 col-sm-10 col-md-8">
            <h3 class="page-section-title">Larry J designs</h3>
            <p>Conformity is the jailer of freedom and the enemy of growth.” ― John F. Kennedy</p>
          </div>
        </div>
      </div>
    </section>




  </header>
  <section class="layout-card container-fluid">
    <div class="row justify-content-center">
      <div class="col-8 col-sm-12 col-lg-10">
        <div class="card-deck">
          <section class="card my-3">
            <a data-toggle="modal" data-target="#site-modal" data-highres="#" href="business_card.png"> <img class="layout-image img-fluid" src="business_card.png" alt="photo sample"></a>
            <div class="card-body">
              <h4 class=" layout-title card-title">Business Cards</h4>
              <p class="card-text layout-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>

            </div>
          </section>
          <section class="card my-3">
            <a data-toggle="modal" data-target="#site-modal" data-highres="#" href="stocklayouts-graphic-design-templates-2.jpg"><img src="stocklayouts-graphic-design-templates-2.jpg" class="card-img-top img-fluid" alt="..."></a>
            <div class="card-body">
              <h4 class="card-title layout-text">Flyers</h4>
              <p class="card-text layout-text"></p>

            </div>
          </section>
          <section class="card my-3">
            <a data-toggle="modal" data-target="#site-modal" data-highres="#" href="website stock.jpg"> <img src="website stock.jpg" class="card-img-top img-fluid" alt="..."></a>
            <div class="card-body">
              <h4 class="card-title layout-title">Webpages</h4>
              <p class="card-text layout-text"> As of this moment we build small webpages, such as porfolios, small business, blogs etc. </p>
            </div>
          </section>
        </div>
      </div>
    </div>
  </section>
  <footer class="site-footer text-light d-flex justify-content-center">
    <section class="layout-social py-5">
      <a class="text-light px-2" href="https://twitter.com/planetoftheweb">
        <i class=" layout-icon fab fa-twitter"></i>
      </a>
      <a class="text-light px-2" href="https://facebook.com/viewsource">
        <i class=" layout-icon fab fa-facebook"></i>
      </a>
      <a class="text-light px-2" href="https://linkedin.com/in/planetoftheweb">
        <i class=" layout-icon fab fa-linkedin"></i>
      </a>
      <a class="text-light px-2" href="https://github.com/planetoftheweb">
        <i class=" layout-icon fab fa-github"></i>
      </a>
      <a class="text-light px-2" href="https://plus.google.com/+RayVillalobos0">
        <i class=" layout-icon fab fa-google-plus"></i>
      </a>
      <a class="text-light px-2" href="https://dribbble.com/planetoftheweb">
        <i class=" layout-icon fab fa-dribbble"></i>
      </a>
      <a class="text-light px-2" href="https://www.flickr.com/photos/planetoftheweb/sets/72157602932636630/">
        <i class=" layout-icon fab fa-flickr"></i>
      </a>
      <a class="text-light px-2" href="https://www.youtube.com/user/planetoftheweb">
        <i class=" layout-icon fab fa-youtube"></i>
      </a>
      <div class="copyright py-4 text-center text-white">
        <div class="container">
          <small>Copyright &copy; Larry J designs 2019</small>
        </div>
      </div>
    </section>

  </footer>
  <article id="site-modal" class="modal fade">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <img data-dismiss="modal" class="img-fluid" src="#" alt="Modal Photo">
      </div>


    </div>
  </article>
  <!-- Optional JavaScript -->
  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  <!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> -->
  <script src="js/bootstrap-4.2.1.js"></script>
  <script src="larryj.js"></script>
</body>

</html>

【问题讨论】:

标签: javascript html css bootstrap-4


【解决方案1】:

这个元素不存在 find('.modal content img')

你有“.modal-content img”这个

【讨论】:

  • 那我该怎么办?
【解决方案2】:

你能试试类似下面的代码吗:

$(function(){

    $('#site-modal').on('show.bs.modal',function(event) {
    var url = $(event.relatedTarget).children().attr('src')
    $('#site-modal')    
        .find('img')
        .attr('src',url )
  });   

});

Image display in a modal

【讨论】:

  • 另外,我注意到锚标记中的属性 data-highres="#" 不包含有效链接。因此,img 元素中的 src 属性指的是值“#”(图像的断开链接)。请在here 中查看此答案。没事吧?
  • 还是不行。数据属性是什么。给我解释一下?
  • data-* 属性用于存储所有 HTML 元素的自定义数据。例如,在您的情况下,您可以在此处引用指向更高分辨率图像的链接。
  • 我需要帮助!!请帮帮我。
  • 好的,伙计,为什么提供的解决方案不适合您,我只是有点困惑,所以请与我们分享您修改的代码。
【解决方案3】:

我已经复制了这个例子,它可以工作:https://jsfiddle.net/ayj0obwh/

我认为您的问题是您在 &lt;head&gt; 甚至在 &lt;html&gt; 标记之外加载 CSS 库。尝试删除它,因为您已经在 &lt;head&gt; 标签上加载了 Bootstrap CSS。

&lt;link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/&gt;

【讨论】:

  • 你是什么意思。我只看到1?我删除了它,我有问题....
  • 在您粘贴的 html 代码之上是这样的:&lt;link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/&gt; &lt;!doctype html&gt; &lt;html lang="en"&gt; 删除第一行,即&lt;link&gt; 标签
【解决方案4】:

这又是我的代码。 Id 它是 CSS 还是没关系。解决这个问题已经好几个星期了。

$(function() {
  $('#site-modal').on('show.bs.modal', function() {
    $(this)
      .find('.modal content img')
      .attr('src', $(event.relatedTarget).data('highres'))
  });
});
@import url('https://fonts.googleapis.com/css?family=Merriweather:300|Source+Sans+Pro:200,400,600');

:root {
  /* 
    --blue: #007bff;
    --indigo: #6610f2;
    --purple: #6f42c1;
    --pink: #e83e8c;
    --red: #dc3545;
    --orange: #fd7e14;
    --yellow: #ffc107;
    --green: #28a745;
    --teal: #20c997;
    --cyan: #17a2b8;
    --white: #fff;
    --gray: #6c757d;
    --gray-dark: #343a40;
    --primary: #007bff;
    --secondary: #6c757d;
    --success: #28a745;
    --info: #17a2b8;
    --warning: #ffc107;
    --danger: #dc3545;
    --light: #f8f9fa;
    --dark: #343a40;

    --breakpoint-xs: 0;
    --breakpoint-sm: 576px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 992px;
    --breakpoint-xl: 1200px;

    --font-family-sans-serif: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";
    --font-family-monospace: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
*/
  /* Override Variables */
  --font-family-sans-serif: 'Source Sans Pro', -apple-system,
    BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
    'Segoe UI Symbol';
	--gray-dark: #404040;}

  /* Page Variables */
  --font-family-serif: Merriweather, serif;
  --color-text: var(--gray-dark);
  --font-family-text: var(--font-family-serif);
	--secondary: #6c757d;
}

family-sans {
  font-family: var(--font-family-sans-serif);
}

body {
  font-family: var(--font-family-text);
  color: var(--color-text);
  font-weight: 200;
	background-image:url(jonathan-bowers-531776-unsplash.jpg);
	 background-repeat: no-repeat;
  background-size: auto;
	background-position:top;
}

.site-header {
  background: url("");
  background-position: center bottom;
  background-repeat: no-repeat;
  background-size: cover;
	;
}

.site-header .layout-hero {
  min-height: 20vh;
}

.site-header .page-section-title .header-title {
  font-size: 3em;
  font-family: var(--font-family-sans-serif);
  font-weight: 200;
}

.site-header .page-section-text.page {
  font-size: 1.2em;
}

.layout-social .layout-icon {
  font-size: 2em;
}


img {
  max-width: 75%;
  height: auto;
	display:block;
	margin-left:auto;
	margin-right:auto;
}

h2,h5{text-align:center;
text-transform:uppercase;
}

h1{font-family:Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", "serif";text-transform: capitalize;}
h3{color:red;}

@media screen and (max-width: 768px) {
  .site-header .navbar-collapse {
    background-color: rgba(0, 0, 0, 0.9);
    padding: 10px;
  }
}



.site-header .nav-link {
  position: relative;
  padding-bottom: 0;
  margin-bottom: 2px;
}

.site-header .nav-link:before {
  content: '';
  position: absolute;
  width: 100%;
  max-width: 100px;
  height: 2px;
  left: 0;
  bottom: 0;
  background-color: var(--red);
  visibility: hidden;
  transform: scaleX(0);
  transition: all 0.3s ease-out;
}

.site-header .nav-link:hover:before {
  visibility: visible;
  left: 0;
	transform: scaleX(1);}

.animated {
  visibility: visible !important;
}
h1{text-transform:uppercase;}
<!doctype html>
<html lang="en"><head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- css style sheet-->
	  
  <!-- Bootstrap CSS -->
    <!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
    <link href="css/bootstrap-4.2.1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
    <link href="larry 2.css" rel="stylesheet" type="text/css">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Hello, world!</title>
</head>
  <body>
  

<header id="page-hero" class="site-header">
    <nav class="navbar navbar-expand-md navbar-dark">

      <div class="container-fluid">
        <a class="navbar-brand" href="#page-hero">
          <i class="fas fa-ankh"></i> LarryJ Designs</a>
      </div>

      <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#myTogglerNav" aria-controls="#myTogglerNav" aria-label="Toggle Navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

      <section class="collapse navbar-collapse align" id="myTogglerNav">
        <div class="navbar-nav">
          <a class="nav-item nav-link" href="index.html">Home</a>
          <a class="nav-item nav-link" href="about3.html">About </a>
          <a class="nav-item nav-link" href="portfolio2.html">Portfolio</a>
          <a class="nav-item nav-link" href="">Contact</a>
        </div>


      </section>


    </nav>


    <section class="layout-hero d-flex align-items-center text-light text-center">
      <div class="container">
        <div class="row justify-content-center">
          <div class="col-11 col-sm-10 col-md-8">
            <h3 class="page-section-title">Larry J designs</h3>
            <p>Conformity is the jailer of freedom and the enemy of growth.” ― John F. Kennedy</p>
          </div>
        </div>
      </div>
    </section>




  </header>
  <section class="layout-card container-fluid">
    <div class="row justify-content-center">
      <div class="col-8 col-sm-12 col-lg-10">
        <div class="card-deck">
          <section class="card my-3">
            <a data-toggle="modal" data-target="#site-modal" data-highres="#" href="business_card.png"> <img class="layout-image img-fluid" src="business_card.png" alt="photo sample"></a>
            <div class="card-body">
              <h4 class=" layout-title card-title">Business Cards</h4>
              <p class="card-text layout-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>

            </div>
          </section>
          <section class="card my-3">
            <a data-toggle="modal" data-target="#site-modal" data-highres="#" href="stocklayouts-graphic-design-templates-2.jpg"><img src="stocklayouts-graphic-design-templates-2.jpg" class="card-img-top img-fluid" alt="..."></a>
            <div class="card-body">
              <h4 class="card-title layout-text">Flyers</h4>
              <p class="card-text layout-text"></p>

            </div>
          </section>
          <section class="card my-3">
            <a data-toggle="modal" data-target="#site-modal" data-highres="#" href="website stock.jpg"> <img src="website stock.jpg" class="card-img-top img-fluid" alt="..."></a>
            <div class="card-body">
              <h4 class="card-title layout-title">Webpages</h4>
              <p class="card-text layout-text"> As of this moment we build small webpages , such as portfolios , small business , blogs etc. </p>
            </div>
          </section>
        </div>
      </div>
    </div>
  </section>
  <footer class="site-footer text-light d-flex justify-content-center">
    <section class="layout-social py-5">
      <a class="text-light px-2" href="https://twitter.com/planetoftheweb">
        <i class=" layout-icon fab fa-twitter"></i>
      </a>
      <a class="text-light px-2" href="https://facebook.com/viewsource">
        <i class=" layout-icon fab fa-facebook"></i>
      </a>
      <a class="text-light px-2" href="https://linkedin.com/in/planetoftheweb">
        <i class=" layout-icon fab fa-linkedin"></i>
      </a>
      <a class="text-light px-2" href="https://github.com/planetoftheweb">
        <i class=" layout-icon fab fa-github"></i>
      </a>
      <a class="text-light px-2" href="https://plus.google.com/+RayVillalobos0">
        <i class=" layout-icon fab fa-google-plus"></i>
      </a>
      <a class="text-light px-2" href="https://dribbble.com/planetoftheweb">
        <i class=" layout-icon fab fa-dribbble"></i>
      </a>
      <a class="text-light px-2" href="https://www.flickr.com/photos/planetoftheweb/sets/72157602932636630/">
        <i class=" layout-icon fab fa-flickr"></i>
      </a>
      <a class="text-light px-2" href="https://www.youtube.com/user/planetoftheweb">
        <i class=" layout-icon fab fa-youtube"></i>
      </a>
      <div class="copyright py-4 text-center text-white">
        <div class="container">
          <small>Copyright &copy; Larry J designs 2019</small>
        </div>
      </div>
    </section>

  </footer>
  <article id="site-modal" class="modal fade">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <img data-dismiss="modal" class="img-fluid" src="#" alt="Modal Photo">
      </div>


    </div>
  </article>
<!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <!-- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> -->
  <script src="js/bootstrap-4.2.1.js"></script>
	  <script src="larryj.js"></script>
</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    相关资源
    最近更新 更多