单击时关闭弹出窗口

时间:2020-09-16 14:37:22

标签: javascript jquery drupal

我有这个小代码可以关闭弹出窗口:

   $('.interop-sidebar_right .icon-close').on('click', function () {
      console.log("close");
      var elem = $('.interop-sidebar_right');
      elem.hide();
    });

但这不起作用:(

这是我的全部文件:

(function ($, Drupal) {

  $('document').ready(function(){

    //Load default sidebar text
    var entity_id = drupalSettings.interop.nid;
    getSidebarRight(entity_id, 'text-1');

    //SVG
    $('.svg-text').on('click', function () {
      var id = $(this).attr('rel');
      getSidebarRight(entity_id, id);
      // Précious line of code <3
      $(this).addClass("svg-style").siblings("text.svg-text").removeClass("text svg-style");
      $("#"+id).show().siblings(".right-sidebar").hide();
    });

    //Arbre decisionnel
    $('#arbre-decisionnel-form input.form-radio').on('click', function () {
      var id = $(this).attr('id');
      var entity_id = $(this).val();
      getSidebarRight(entity_id, id);
    });

    //Ajax get sidebar html
    function getSidebarRight(entity_id, id) {
      $.ajax({
        url : '/asip_interop/getInfosServices/' + entity_id + '/' + id,
        type : 'GET',
        dataType : 'html',
        success : function(html, status){
          if(html.length > 0) {
            $('.aside-home-bar .region-right-sidebar').html(html);
          }
        }
      });
    }


     // Close Modale by clicking on the cross X
    $('.interop-sidebar_right .icon-close').on('click', function () {
      console.log("close");
      var elem = $('.interop-sidebar_right');
      elem.hide();
    });
  });

})
(jQuery, Drupal, drupalSettings);

还有html:

<div class="interop-sidebar_right -2" id="styckyRightCol">
    <h2> Informations services  <span class="icon icon-close"> </span></h2>
    <div class="region-right-sidebar_bloc-infos">
        <span class="icon icon-info"></span>
        <p>Cliquez sur le symbole pour faire apparaître des Informations et des liens. </p>
    </div>
    <div class="region-right-sidebar_body">
        <h3>{{ titre }}</h3>
        {{ body|replace_shortcode|replace_shortlink|raw  }}

        {% if links or docs %}
          <div class="region-right-sidebar_links">
                {% for link in links %}
                    <p class="icon-left icon-attach">
                        <a href="{{ link.url }}">{{ link.title }}</a>
                    </p>
                {% endfor %}
                {% for doc in docs %}
                    <p class="icon-left icon-download">
                        <a href="{{ file_url(doc.entity.field_me_document_file.entity.uri.value) }}" target="_blank">{% if doc.entity.field_me_document_title.value %} {{ doc.entity.field_me_document_title.value }} {% else %} {{ doc.entity.name.value }} {% endif %}</a>
                    </p>
                {% endfor %}
          </div>
        {% endif %}
    </div>
</div>

有什么帮助吗?

谢谢

1 个答案:

答案 0 :(得分:0)

尝试一下,它应该对您有用

$(document).on('click','.interop-sidebar_right .icon-close', function () {
     $('#styckyRightCol').hide();
});