“ javascript:void()仅呈现为” void()“

时间:2019-06-02 10:35:35

标签: javascript html wordpress

它曾经在过去和当前的其他网站上都可以使用,但是更新此网站后它将不再起作用。我收到一条带有woocommerce通知的弹出消息,只是说该商品已添加到购物车,并带有一个使用javascript:void方法的关闭按钮。但是,它不再起作用,当我查看源代码时,它只是以“ void(0)”而不是“ javascript:void(0)”

放置

我尝试了其他方法,例如仅使用#。什么都没有。盒子不会关闭。

  <div id="woocommerce-message">
   <div class="close">
  <a href="javascript:void(0)" class="closeEmbtn" onclick="closeEm()" 
title="Close Notification"><i class="fa fa-times" aria-hidden="true"></i> 
</a></div>

<div class="success-cart">
<div class="woocommerce-message">
<?php foreach ( $messages as $message ) : ?>
<?php echo wp_kses_post( $message ); ?>
<?php endforeach; ?>
</div>
</div>

<div class="message-cart-buttons">
<a class="button" href="/cart/">View Cart/Checkout</a>
<a href="javascript:void(0)" class="button" onclick="closeEm()">Continue Shopping</a>
</div>
</div>

<script type="text/javascript">
function closeEm() {
    document.getElementById("woocommerce-message").style.display = "none";
}
</script>

当他们单击关闭按钮时,我只想关闭/隐藏“ woocommerce-message” div。

-编辑- 我尝试了另一种方法

<div class="close">
<a class="closeEmbtn" onclick="closeEm()" href="#" title="Close Notification"><i class="fa fa-times" aria-hidden="true"></i></a></div>



<script>
function closeEm() {
var x = document.getElementById("woocommerce-message");

x.style.display = "none";

}
</script>

但这是源代码中也没有显示“ onclick =“。 WordPress中是否有可能阻止它的东西?

1 个答案:

答案 0 :(得分:0)

我想出了解决新脚本功能的方法

class PartialsController < ApplicationController
  skip_before_action :verify_authenticity_token

  def update_school_and_teacher_code
    school = School.find_by_id(params[:id])
    if school.school_code != params[:school_code]
      School.transaction do 
        school.update_attributes!(:school_code => params[:school_code])        
        teacher = Teacher.find(params[:teacher_id])
        teacher.update_attributes!(:teacher_code => school.school_code)
        student = Student.find(params[:student_id])
        student.update_attributes!(:student_code => school.school_code) 
        render json: { message: ' data updated '}
      end
    else
      render json: { message: ' data not updated '}
    end
    rescue => e
      render json: { error: ' data not found '}
  end
end

则不必依赖javscript:void(0)并在html中单击。 但是我仍然很想知道为什么这些元素突然从输出代码中消失了