繁体   English   中英

当光标位于按钮上时显示一条消息(并禁用单击)

[英]Display a message when the cursor is ON the button (and disable the click)

的JavaScript

    $(function(){
        $('.select-another-button').each(function(){
          $(this).bind('click', function(e){
            $('#message').show()
            setTimeout(function(){ $('#message').hide() }, 300000);
            e.preventDefault();
            fileBrowser(this);
            return false;
          });
        });
      });

的HTML

 <a href="#"
        title="{% trans "Send email - rejected file(s)" %}"
        class="btn btn-icon select-another-button"
        data-url="{% url "messaging:send" request_id=object.pk %}">
        <i class="material-icons">assignment_late</i>
         <div class='alert alert-success' id='message'>
            The message was sent to the client. Please wait 5 minutes before sending the message again.
         </div>
    </a>

Django的

app_name = 'messaging'
urlpatterns = [
    ...

    url(r'^send/(?P<request_id>[0-9]+)/$',
        send, name='send'),
]

@staff_member_required
@csrf_exempt
def send(request, request_id=None):
    req= Request.objects.get(pk=request_id)
    request_folders = req.folder.all_files.all()
    context = []

    for doc in request_folders:
        if doc.meta.state == u'rejected':
            context.append(doc)

    if context:
        ctx = {'request': req}
        EmailFromTemplate('document-refusal', extra_context=ctx)\
            .send_to(req.customer.user)

    return HttpResponse('')

此代码的目的是创建一个按钮,该按钮将在特定条件下发送电子邮件。 我的弱点可能在于HTML和jS部分。 用户单击按钮后,我希望等待五分钟,然后他才能再次发送消息。 因此,一旦使用按钮,我必须将其关闭五分钟,然后显示消息:' 消息已发送到客户端。 请等待5分钟,然后再次发送消息。 “当光标的按钮。 如何修改JS部分,使其可以执行我想要的操作?


更新资料

      <div class="title-actions">
        {% if not object.is_readonly %}
        {# TODO: apply perms #}
        <a href="#"
          id="id_select_request_document"
          title="{% trans "Select file(s)" %}"
          class="btn btn-icon select-button"
          data-turbolinks="false"
          data-save-label="{% trans "Ok" %}"
          data-close-label="{% trans "Cancel" %}"
          data-copy-to="{{ folder.pk }}"
          data-reload="true"
          data-url="{% url "documents:ajax-select" folder_id=object.customer.folder.pk %}">
          <i class="material-icons">folder</i>
        </a>
        {# TODO: apply perms #}
        {# if permissions.has_add_children_permission and not folder.is_root #}
        <a href="#"
          id="id_upload_request_document"
          title="{% trans "Upload file(s)" %}"
          class="btn btn-icon upload-button"
          data-turbolinks="false"
          data-url="{% url "documents:ajax-upload" folder_id=folder.pk %}"
          data-complete-post="{% url "requests:validate-requirements" pk=object.pk %}"
          data-max-uploader-connections="1">
          <i class="material-icons">cloud_upload</i>
        </a>
        <div class="wrapper">
            <div id="overlay"></div>
            <a href="#"
               title="{% trans "Send email - rejected file(s)" %}"
               class="btn btn-icon select-another-button"
               data-url="{% url "messaging:send" request_id=object.pk %}">
                <i class="material-icons">assignment_late</i>
                <div class='alert alert-success' id='send-message' style="display: none;">
                    <p>
                    The message was sent to the client. Please wait 5 minutes <br> before sending the message again.
                    </p>
                </div>
            </a>
        </div>
        {% endif %}
        {% if request.user.is_superuser %}
        <a href="{{ folder.get_admin_directory_listing_url_path }}" class="btn-icon"><i class="material-icons">settings</i></a>
        {% endif %}
      </div>

修改之前,我的显示正确 ,但是现在我的显示错误

我不知道它是否很好,但是我将以下代码块放在了.html文件的顶部。

<script type="text/css">

    .wrapper{
      position: relative;
      display: inline-block;
    }
    #overlay{
      display: none;
      position: absolute;       
      top: 0;
      left: 0;
      opacity: .1;
      background-color: blue;
      height: 100%;
      width: 100%;
    }

的CSS

.title-actions {
  float: right;
  height: 50px;
  margin-top: 13px; }
  .title-actions a {
    transition: background 0.3s ease; }
    .title-actions a.btn {
      padding: 2px 14px;
      line-height: 26px;
      max-height: 28px;
      position: relative;
      top: -1px;
      margin-left: 8px; }
    .title-actions a:hover {
      background: #4382b5; }
  .title-actions span {
    color: #444;
    background: #e6e6e6;
    padding: 6px 10px;
    border-radius: 3px;
    float: none;
    position: relative;
    margin-left: 6px; }
  .title-actions .btn {
    padding: 2px 14px;
    line-height: 26px;
    max-height: 28px;
    position: relative;
    top: -1px;
    margin-left: 8px; }
  .title-actions .btn-icon {
    background: transparent;
    position: relative;
    color: #3e5366;
    text-align: center;
    display: inline-block;
    padding: 0 !important;
    transition: color 0.3s ease;
    box-shadow: none !important;
    margin-top: -16px;
    margin-left: 6px; }
    .title-actions .btn-icon i {
      font-size: 35px;
      line-height: 20px;
      position: relative;
      top: 12px; }
    .title-actions .btn-icon:hover {
      color: #4382b5;
      background: transparent; }
  .title-actions .badge .material-icons {
    font-size: 1.2em;
    line-height: 0;
    position: relative;
    top: 4px; }

您需要对代码进行大量更改。 假设您只有1个元素,其id="message"id="message"

从您的JQuery代码开始。

$(function(){
  $('.select-another-button').each(function(){
    $(this).bind('click', function(e) {
      $(this).attr('disabled','true'); //disables the button
      $('#overlay').show(); //after disabling show the overlay for hover
      setTimeout(function(){ 
        $(this).attr('disabled','false'); //enables after 5mins
        $('#overlay').hide(); //hide the overlay
      }, 300000);
      e.preventDefault();
      fileBrowser(this);
      return false;
    });
  });
});

$("#overlay").hover(function(){
    $('#message').show();
},function(){
    $('#message').hide();
});

由于禁用的按钮不能具有hover事件,因此您需要在按钮上放置透明的覆盖并在其悬停上显示#message

的HTML

<div class="wrapper">
  <div id="overlay"></div>
  <a href="#"
     title="{% trans "Send email - rejected file(s)" %}"
     class="btn btn-icon select-another-button"
     data-url="{% url "messaging:send" request_id=object.pk %}">
    <i class="material-icons">assignment_late</i>
    <div class='alert alert-success' id='message' style="display: none;">
    The message was sent to the client. Please wait 5 minutes before sending the message again.
    </div>
  </a>
</div>

当然,还要更改CSS,以确保将overlay正确放置在按钮上,然后将其禁用。

.wrapper{
  position: relative;
  display: inline-block;
}
#overlay{
  display: none;
  position: absolute;       
  top: 0;
  left: 0;
  opacity: .1;
  height: 100%;
  width: 100%;
}

 $(function(){ $('.select-another-button').each(function(){ $(this).bind('click', function(e) { $(this).attr('disabled','true'); $('#overlay').show(); setTimeout(function(){ $(this).attr('disabled','false'); $('#overlay').hide(); }, 300000); e.preventDefault(); fileBrowser(this); return false; }); }); }); $("#overlay").hover(function(){ $('#message').show(); },function(){ $('#message').hide(); }); 
 .wrapper{ position: relative; display: inline-block; } #overlay{ display: none; position: absolute; top: 0; left: 0; opacity: .1; height: 100%; width: 100%; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="wrapper"> <div id="overlay"></div> <a href="#" title="{% trans "Send email - rejected file(s)" %}" class="btn btn-icon select-another-button" data-url="{% url "messaging:send" request_id=object.pk %}"> <i class="material-icons">assignment_late</i> <div class='alert alert-success' id='message' style="display: none;"> The message was sent to the client. Please wait 5 minutes before sending the message again. </div> </a> </div> 

暂无
暂无

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

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