我无法在代码中使用jAlert?

时间:2016-07-02 12:43:13

标签: javascript jquery

我无法使用jAlert对话框,我正在尝试使用jAlert替换所有警报框,但浏览器会抛出此错误。

jQuery.Deferred exception: jAlert is not defined ReferenceError: jAlert is not defined
at HTMLDocument.<anonymous> (http://localhost:8080/Kn1/insertion_checking.js:69:13)
at j (http://localhost:8080/Kn1/jquery-3.0.0.min.js:2:29588)
at k (http://localhost:8080/Kn1/jquery-3.0.0.min.js:2:29902) undefined

请帮我使用jAlert。谢谢!!这是代码

//Inserting jquery here
var jq = document.createElement("script");

jq.addEventListener("load", mySubmitFunction); // pass my hoisted function
jq.src = "jquery-3.0.0.min.js";
document.querySelector("head").appendChild(jq);

var instance1 = 0 ;
var instance2 = 0 ;
var x = 0 ;

//work_over_history: To check for each new element added
function add1_check(){
instance1++ ;
console.log("checking: " +instance1) ;
}

//crane_job_history: To check for each new element added
function add2_check(){
instance2++ ;
console.log("checking: " +instance2) ;
}


// Function for checking the from and to date 
function mySubmitFunction(){
    console.log("DATE:") ;
    console.log("instance zero area") ;

    var from_work_date = document.getElementById("from_work").value ;
    var to_work_date = document.getElementById("to_work").value ;
    console.log(from_work_date)  ;
    console.log(to_work_date) ;
    console.log(typeof(to_work_date));

    var fw_date = new Date(from_work_date) ;
    console.log(typeof(fw_date)) ;
    var to_date = new Date(to_work_date);
    console.log(typeof(to_date)) ;

    if( fw_date >= to_date ){

        console.log("Error") ;
        alert(" Check Your Working History : \"From Date\" entered is Larger than \"To Date\"") ;
        return false ;
    }
    if( instance1 > 0 ){

    while(x !== instance1 ){

    alert("diagram") ;
    x++ ;
    var from_work_date = document.getElementById("from_work" +x).value ;
    var to_work_date = document.getElementById("to_work" +x).value ;
    console.log("From:" +from_work_date)  ;
    console.log("To" +to_work_date) ;
    console.log(typeof(to_work_date));

    var fw_date = new Date(from_work_date) ;
    console.log(typeof(fw_date)) ;
    var to_date = new Date(to_work_date);
    console.log(typeof(to_date)) ;

    if( fw_date >= to_date ){

        console.log("Error") ;
        console.log("Game") ;
        $(document).ready( function() {
        jAlert("Please Check Your Work Hitory","Alert Dialog") ;
    });
    return false ;
    } //End of if statement     
   } // End of while statement x != instance1
 }// End of if statement of instance1

} // mySubmitFunction()

1 个答案:

答案 0 :(得分:0)

您必须在HTML页面中加载您的库:

<script type="text/javascript" src="jalert.js"></script>

(如果jalert.js与HTML页面位于同一目录中)