【问题标题】:Creating auto confirmation , with jquery and javascript使用 jquery 和 javascript 创建自动确认
【发布时间】:2018-06-18 20:07:10
【问题描述】:

我刚刚创建了一个自动预约预约功能 它在 jsFiddle 上完美运行 问题是当我在与 firefox 相同的 chrome 控制台上通过它时出现错误

错误:

未捕获的类型错误无法读取 'null' 的属性 'on'

这是函数 jQ+JS:

(function(){
$('a.dispo').on('click', function(){
var hold= setInterval(function(){
var submitclassform = document.getElementById('ajax_confirm_action');
if (submitclassform) {
          var button = document.getElementById('ajaxConfirmCall_submit');
          button.click();
          alert("confimation success ! ");
          clearInterval(hold);
    }
    },500);
})})();

HTML 代码:

<ul>
<li class="overable initialised">2018-06-12
    <a class="dispo" id ="test" type="button" href="javascript:void(0)" 
   onclick="AC">08<i>:30</i></a>
    <a class="dispo" type="button" href="javascript:void(0)" 
  onclick="AC">09<i>:00</i></a>
    <a class="dispo" type="button" href="javascript:void(0)" 
  onclick="AC">09<i>:30</i></a>
</li>
</ul>
<p>
After choosing appointment time , scenario 
Confirmation Button POP Up ! 
</p>
<form action="action.php" id="ajax_confirm_action">

 <input type="submit" name="conf" value="CONFIRMATION " 
 id="ajaxConfirmCall_submit" >
 </form> 

【问题讨论】:

    标签: javascript jquery html google-chrome firefox


    【解决方案1】:

    如果您将 javascript 放在呈现的 html 之前(即在标签中),那么您的脚本会在 DOM 节点被写入之前执行。因为该节点还不存在,所以会出现 NULL 错误。

    尝试将您的 javascript 移动到文档的末尾(即标记之前)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 1970-01-01
      • 2022-12-08
      • 1970-01-01
      相关资源
      最近更新 更多