简体   繁体   English

Datepicker(jQuery)无法在加载特定的javascript函数时加载

[英]Datepicker(jQuery) not loading on loading specific javascript function

I have a peculiar problem. 我有一个特殊的问题。

The datepicker does not work when I load a particular javascript function. 当加载特定的javascript函数时,日期选择器不起作用。

Code: Datepicker 代码:日期选择器

$(function() {
    $('input.datepicker').datepicker();
    });

    $(function () {
    $("#txtFrom").datepicker({
    numberOfMonths: 1,
    onSelect: function (selected) {
        var dt = new Date(selected);
        dt.setDate(dt.getDate() + 1);
        $("#txtTo").datepicker("option", "minDate", dt);
    }
    });
    $("#txtTo").datepicker({
    numberOfMonths: 1,
    onSelect: function (selected) {
        var dt = new Date(selected);
        dt.setDate(dt.getDate() - 1);
        $("#txtFrom").datepicker("option", "maxDate", dt);
    var a = $("#txtTo").datepicker('getDate').getTime();
    b = $("#txtFrom").datepicker('getDate').getTime();
    c = (a - b) / (1000 * 60 * 60 * 24);
    $("#rem").val(c);
            }
    });     
});

Javascript Function(this executes onLoad) Javascript函数(此函数执行onLoad)

init();
var a;
function init(){
var db = openDatabase('CBDB', '1.0', 'mySpecialDatabaseThatWontWork',10*1024*1024);
db.transaction(function (tx) {
    tx.executeSql('SELECT * FROM user',[], function (tx, results) {
        var rows = results.rows;
        for (var index = 0; index < rows.length; index++) {
            var x = rows.item(index);
            a = results.rows.item(index).empid;
        }
        next();
    });});              
}   
function next(){
var db = openDatabase('CBDB', '1.0', 'mySpecialDatabaseThatWontWork',10*1024*1024);
db.transaction(function (tx) {
    console.log("global"+a);
    tx.executeSql('SELECT * FROM login WHERE manager=?',[a], function (tx, results) {
        var rows = results.rows;
        var msg=" ";
        for (var index = 0; index < rows.length; index++) {
            msg +="<option>"+results.rows.item(index).name+","+results.rows.item(index).empid+"</option>"
        }
        var total= "<div class=\"widh1\"><div style=\"text-align: left;\" class=\"margn1\"><p class=\"dateText\">Employee</p><div class=\"selectParent\"><select id=\"type\" class=\"apply1Text\">"+msg+"</select></div></div></div>";
        document.querySelector('#status').innerHTML +=  total;
    });});
}

I'm not able to spot the mistake. 我无法发现错误。 Also the javascript function loads after the HTML content is loaded on to the page. HTML内容加载到页面后,JavaScript函数也会加载。

The problem was that the queryselector was replacing the the entire . 问题是queryselector正在替换整个。 I changed it to getElementById. 我将其更改为getElementById。 Now its working fine. 现在它的工作正常。

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

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