简体   繁体   English

模态窗口将仅使用第一个元素打开,而不使用第二个或第三个元素打开

[英]modal window will only open using the first element, not the second or the third

Html for the multiple images (I am trying to use all of the images with one modal) and have to modal display specific information based on the image that is chosen. 用于多个图像的HTML(我正在尝试使用一个模态使用所有图像),并且必须根据所选择的图像模态显示特定信息。

  <div id = "items">
  <li id="item">
    <a><img src="images/items/Meat Nugget.png" />
  </li>
  <li id="item">
    <a><img src="images/items/Bustling Fungus.png" />
  </li>

JavaScript for making taking in the trigger of clicking on the element 使用JavaScript触发点击元素的触发器

(function(){
  var $content = $('#share-options').detach();  

  $('#item').on('click', function() {           
    modal.open({content: $content, width:340, height:300});
  });
}());

This is because ID is unique to a single element, so each page can only have one element with that ID. 这是因为ID对于单个元素是唯一的,因此每个页面只能具有一个具有该ID的元素。 You can fix this by using class, you can use the same class on multiple elements. 您可以使用类来解决此问题,也可以在多个元素上使用相同的类。

<div id = "items">
  <li class="item">
    <a><img src="images/items/Meat Nugget.png" />
  </li>
  <li class="item">
    <a><img src="images/items/Bustling Fungus.png" />
  </li>

When referencing a class you'll need to use the . 引用类时,您需要使用。 (class selector) instead of a # (ID selector) (类选择器)而不是#(ID选择器)

$('.item').on('click', function() {           
    modal.open({content: $content, width:340, height:300});
  });
}());

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

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