【问题标题】:How to open bootstrap modalbox by clicking on the card image in angularjs project如何通过单击angularjs项目中的卡片图像打开引导模式框
【发布时间】:2020-05-26 13:35:09
【问题描述】:

我正在为我的 angularjs 项目编写代码,其中 UI 的一部分有卡片。所以我想通过点击卡片图像打开一个模态框。 目前我在图像下方创建了一个按钮,单击该按钮将打开模态框。 这工作正常。但是我不想点击按钮,而是点击卡片图像,它应该打开模式框。我在下面附上当前代码。任何有关这方面的帮助都将是非常可观的。谢谢你

<div class="col-md-4 clearfix d-none d-md-block">
            <div class="card mb-2">
              <div class="avatar-wrapper">
                <img class="profile-pic" src="/assets/images/abc.jpg" />
                <div class="upload-button">
                 </div>               
              </div>

              <div class="card-body">            

         <h4> <button type="button" class="card-title text-center font-weight-bold" data-toggle="modal" data-target="#basicExampleModal3">
            abc receipe </button>  </h4>
                <h3 class="description">This is short description in the card body.hio dvdjvd sscg sdgscsc sgssd sdjg c edsc sdcfsc dfkopseuccs sc</h3 >     
                 <div class= "modal fade" id="basicExampleModal3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel3"
            aria-hidden="true">
            <div class="modal-dialog modal-lg" role="document">
              <div class="modal-content">
                <div class="modal-header">
               <h5 class="modal-title" id="exampleModalLabel3">Receipe-abc by dfgr</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>

                <div class="modal-body ">
                  <img class="profile-pic" src="/assets/images/abc.jpg" />
                 <p> Modal Box Description.                 
                  sdc
                  dfvdv
                  sscg sdgscsc dfvfd
                 </p>
                </div>                
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>                  
                </div>             
              </div>
            </div>
          </div>

</div>
            </div>
          </div>

【问题讨论】:

    标签: html angularjs bootstrap-4 bootstrap-modal angular-ui-bootstrap


    【解决方案1】:

    在图片元素中添加data-toggle="modal" data-target="#basicExampleModal3",像这样

    <img class="profile-pic" src="/assets/images/abc.jpg"  data-toggle="modal" data-target="#basicExampleModal3"/>
    

    检查sn-p,现在点击图片打开模态

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <div class="col-md-4 clearfix  d-md-block">
      <div class="card mb-2">
        <div class="avatar-wrapper">
          <img class="profile-pic" src="/assets/images/abc.jpg" data-toggle="modal" data-target="#basicExampleModal3" />
          <div class="upload-button">
          </div>
        </div>
    
        <div class="card-body">
    
          <h4> <button type="button" class="card-title text-center font-weight-bold">
              abc receipe</button> (click on button wont work, click on image to check) </h4>
          <h3 class="description">This is short description in the card body.hio dvdjvd sscg sdgscsc sgssd sdjg c edsc sdcfsc dfkopseuccs sc</h3>
          <div class="modal fade" id="basicExampleModal3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel3" aria-hidden="true">
            <div class="modal-dialog modal-lg" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabel3">Receipe-abc by dfgr</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
    
                <div class="modal-body ">
                  <img class="profile-pic" src="/assets/images/abc.jpg" />
                  <p> Modal Box Description.
                    sdc
                    dfvdv
                    sscg sdgscsc dfvfd
                  </p>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
              </div>
            </div>
          </div>
    
        </div>
      </div>
    </div>

    【讨论】:

    • 非常感谢您的宝贵时间。我将 data-toggle="modal" data-target="#basicExampleModal3" 添加到图像元素中。但它不起作用。所以将此元素添加到卡片 div 中。它起作用了。感谢这个想法。
    • @MIDHUNBOSEK 你确定它没有用,但是我制作的 sn-p 对图像点击有效。
    猜你喜欢
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多