onDOMReady不能正常工作

时间:2017-11-19 16:42:54

标签: javascript datepicker

我有一个自动保存(没有保存按钮)日期值的表单。我的表单还有一个添加按钮来插入新条目。我有一个datepicker按钮,以便插入日期。当我按下添加按钮时,datwpicker按钮会在所有条目中从我的表单中消失。 我相信这部分代码是造成这个问题的原因:

function onDOMReady(fn,ctx){
      var ready,timer;
      var onStateChange = function(e){ 
        if(e&&e.type == "DOMContentLoaded"){
          fireDOMReady()
        } else if(e&&e.type=="load"){
          fireDOMReady()
        } else if(document.readyState){
          if((/loaded|complete/).test(document.readyState)){
            fireDOMReady()}else if(!!document.documentElement.doScroll){
              try { 
                ready||document.documentElement.doScroll('left')
              } catch(e) { 
                return
              }
              fireDOMReady()
            }
          }
        };
        var fireDOMReady = function(){ 
          if(!ready){
            ready = true;
            fn.call(ctx||window);
            if(document.removeEventListener)
              document.removeEventListener("DOMContentLoaded",onStateChange, false);
            document.onreadystatechange=null;
            window.onload=null;
            clearInterval(timer);
            timer=null
          }
        };
        if(document.addEventListener)
          document.addEventListener("DOMContentLoaded",onStateChange,false);
          document.onreadystatechange=onStateChange;
          timer=setInterval(onStateChange,5);
          window.onload=onStateChange
        };

// This is called when the page loads, it searches for inputs where the class is 'datepicker'
onDOMReady(function(){

  // Search for elements by class
  var allElements = document.getElementsByTagName("*");
  for (i=0; i<allElements.length; i++) {
    var className = allElements[i].className;
    if (className=='datepicker' || className.indexOf('datepicker ') != -1 || className.indexOf(' datepicker') != -1) {
      // Found one! Now lets add a datepicker next to it  
      var a = document.createElement('a');
      a.href='#';
      a.className="datepickershow";
      a.setAttribute('onclick','return showDatePicker("' + allElements[i].id + '")');
      var img = document.createElement('img');
      img.src='calendar.png';
      img.style.height='17px';
      img.style.width='17px';      
      img.title='Show calendar';
      a.appendChild(img);
      insertAfter(a, allElements[i]);
    }
  }
});

当我添加新记录时,datepicker更加便宜。我使用这段代码:

<?php
    echo 'onDOMReady(fn,ctx){var ready,timer;var onStateChange=function(e){if(e&&e.type=="DOMContentLoaded"){fireDOMReady()}else if(e&&e.type=="load"){fireDOMReady()}else if(document.readyState){if((/loaded|complete/).test(document.readyState)){fireDOMReady()}else if(!!document.documentElement.doScroll){try{ready||document.documentElement.doScroll(&quot;left&quot;)}catch(e){return}fireDOMReady()}}};var fireDOMReady=function(){if(!ready){ready=true;fn.call(ctx||window);if(document.removeEventListener)document.removeEventListener("DOMContentLoaded",onStateChange,false);document.onreadystatechange=null;window.onload=null;clearInterval(timer);timer=null}};if(document.addEventListener)document.addEventListener("DOMContentLoaded",onStateChange,false);document.onreadystatechange=onStateChange;timer=setInterval(onStateChange,5);window.onload=onStateChange}';


    session_start();
    include "classes.php";
    $functions=new classes;

    $id_proswpiko=trim($_REQUEST["id"]);
    $now=date('Y-m-d');
    $res=$functions->query("INSERT INTO descent(id_staff,id_reason,start_date,duration) VALUES ('$id_staff',1,'$now','4')");

    $functions->create_descent_screen($id_staff);

?>

我回应你看到的功能,但我得到了功能的片段。我还能做什么?

0 个答案:

没有答案