从库在自定义div中追加函数

时间:2018-12-03 06:31:37

标签: jquery datepicker

我是jquery的新手,这意味着我正在学习它。我一直在处理简单的ajax代码,因为我的规范更多的是PHP,而不是jquery

在这里,我需要自定义一个开放源代码的jquery datepicker库,而不是大库并且没有大的更改。

此日期选择器仅在单击按钮后通过jquery嵌入了该按钮,或者在hovering输入字段中显示日历。摘录已附加。一切正常。

我只需要-在所需的div中append日历即可。

因此,需要自定义datepicker库。我尝试过这个。例如,要直接附加日历的特定div-#calendar,我正在尝试使用append包含在此div库中的每个函数。例如

$('#calendar').getCalendarDivString();

但不起作用。

jQuery Datepicker库

function getCalendarDivString(t) {
    var e = '<div id="ndp-nepali-box" class="ndp-corner-all" style="display:none">'
    return e += '<span id="ndp-target-id" style="display:none"></span>', e += '<div class="ndp-corner-all ndp-header">', e += '<a href="javascript:void(0)" id="prev" title="Previous Month" class="ndp-prev"></a>', e += '<a href="javascript:void(0)" id="next" title="Next Month" class="ndp-next"></a>', e += '<span id="currentMonth"></span>', e += "</div>", e += '<div id="npd-table-div">', e += "<table>", e += '<tr class="ndp-days">', e += "<th>आ</th>", e += "<th>सो</th>", e += "<th>मं</th>", e += "<th>बु</th>", e += "<th>बि</th>", e += "<th>शु</th>", e += "<th>श</th>", e += "</tr>", e += "</table>", e += "</div>", e += "</div>"
}

function showNdpCalendarBox(t) {
    if (npdCalendarVisible) hideCalendarBox(!1)
    else {
        ndpData[t] && (ndpAttr = ndpData[t])
        var e = $("#" + t).val()
        $("#ndp-target-id").html(t)
        var n = $("#" + t).offset()
        $("#ndp-nepali-box").css("top", n.top + $("#" + t).outerHeight()), $("#ndp-nepali-box").css("left", n.left), showCalendar(e), npdCalendarVisible = !0
    }
}

function setSelectedDay(t) {
    var e = $("#ndp-target-id").html()
    $("#" + e).val(t), ndpAttr.ndpEnglishInput && $("#" + ndpAttr.ndpEnglishInput).val(BS2AD(t)), hideCalendarBox()
}

function showCalendar(t) {
    $("#ndp-nepali-box table").find("tr:gt(0)").remove(), "" === t ? $("#ndp-nepali-box table").append(getDateTable("")) : $("#ndp-nepali-box table").append(getDateTable(t)), "block" == $("#ndp-nepali-box").css("display") && $("#ndp-nepali-box").hide(), $("#ndp-nepali-box").fadeIn(100)
}

function getDateTable(t) {
    var e = "",
        n = ""
    if ("" === t) {
        var a = getNepaliDate()
        return e = getMonthParameters(a), n = getDateRows(e[0], e[1], e[2], e[3], e[4])
    }
    return e = getMonthParameters(t), n = getDateRows(e[0], e[1], e[2], e[3], e[4])
}

function performSelectMonth(t) {
    showCalendar((ndpAttr.npdYear ? $("#npd-year-select").val() : t) + "-" + $("#npd-month-select").val() + "-01")
}

function performSelectYear(t) {
    showCalendar($("#npd-year-select").val() + "-" + (ndpAttr.npdMonth ? $("#npd-month-select").val() : t) + "-01")
}

function getMonthSelect(t, e) {
    var n = getNepaliMonthsInNepali(),
        a = '<select id="npd-month-select" onchange="performSelectMonth(' + e + ')">'
    return n.forEach(function(e, n) {
        a += '<option value="' + (n + 1) + '"' + (n + 1 == t ? " selected" : "") + ">" + e + "<li>"
    }), a += "<select>"
}

function getYearSelect(t, e, n) {
    var a = '<select id="npd-year-select" onchange="performSelectYear(' + t + ')">'
    for (i = Math.round(n / 2) > 0 && parseInt(e) - Math.round(n / 2) >= 2e3 ? parseInt(e) - Math.round(n / 2) : 2e3; i <= (Math.round(n / 2) > 0 && parseInt(e) + Math.round(n / 2) <= 2090 ? parseInt(e) + Math.round(n / 2) : 2090); i++) a += '<option value="' + i + '"' + (e == i ? " selected" : "") + ">" + englishNo2Nep(i) + "<li>"
    return a += "<select>"
}

function getMonthParameters(t) {
    var e = t.split("-"),
        n = e[0],
        a = e[1],
        s = ndpAttr.npdYearCount || 0
    ndpAttr.npdMonth && ndpAttr.npdYear ? $("#currentMonth").html(getMonthSelect(a, n) + getYearSelect(a, n, s)) : ndpAttr.npdMonth ? $("#currentMonth").html(getMonthSelect(a, n) + " " + englishNo2Nep(n)) : ndpAttr.npdYear ? $("#currentMonth").html(getNepaliMonth(a - 1) + " " + getYearSelect(a, n, s)) : $("#currentMonth").html(getNepaliMonth(a - 1) + "&nbsp;" + englishNo2Nep(n)), nYear = pYear = n, nMonth = parseInt(a, 10) + 1, nMonth > 12 && (nYear++, nMonth = "01"), pMonth = parseInt(a, 10) - 1, pMonth < 1 && (pYear--, pMonth = "12"), $("#prev").attr("onclick", "showCalendar('" + pYear + "-" + pMonth + "-01')"), $("#next").attr("onclick", "showCalendar('" + nYear + "-" + nMonth + "-01')")
    var r = e[2],
        i = numberOfBsDays(n, a - 1),
        d = new NepaliDateConverter,
        o = a + "/1/" + n,
        h = d.bs2ad(o),
        p = h.split("-"),
        l = p[0],
        u = p[1],
        b = p[2],
        c = new Date(l, u - 1, b),
        g = c.getDay()
    return [g, i, n, a, r]
}

function getDateRows(t, e, n, a, s) {
    for (var r = getNepaliDate(), i = r.split("-"), d = i[0], o = get2DigitNo(i[1]), h = get2DigitNo(i[2]), p = "", l = 0; t + e > l; l++) {
        l % 7 === 0 && (p += "<tr>")
        var u = l - t + 1,
            b = "" + n + "-" + get2DigitNo(a) + "-" + get2DigitNo(u),
            c = ""
        c = n == d && get2DigitNo(a) == o && h == get2DigitNo(u) ? "ndp-selected" : u == s ? "ndp-current" : "ndp-date", ndpAttr.disableDaysBefore && parseInt(ndpAttr.disableDaysBefore) > 0 && (ndpAttr.disableBefore = getNepaliFormat(BsAddDays(getNepaliFormat(getNepaliDate()), -1 * parseInt(ndpAttr.disableDaysBefore)))), ndpAttr.disableDaysAfter && parseInt(ndpAttr.disableDaysAfter) > 0 && (ndpAttr.disableAfter = getNepaliFormat(BsAddDays(getNepaliFormat(getNepaliDate()), parseInt(ndpAttr.disableDaysAfter)))), t > l ? p += "<td></td>\n" : (p += "<td class='" + c + "'>", p += ndpAttr.disableAfter && BsDatesDiff(ndpAttr.disableAfter, getNepaliFormat(b)) > 0 || ndpAttr.disableBefore && BsDatesDiff(ndpAttr.disableBefore, getNepaliFormat(b)) < 0 ? "<a class=\"ndp-disabled\" href='javascript:void(0)'>" + englishNo2Nep(u) + "</a>" : "<a href='javascript:void(0)' onclick=\"setSelectedDay('" + b + "')\">" + englishNo2Nep(u) + "</a>", p += "</td>\n"), l % 7 == 6 && (p += "</tr>\n")
    }
    return p
}

function hideCalendarBox(t) {
    t = void 0 !== t ? t : !0, $("#ndp-nepali-box").fadeOut(100), npdCalendarVisible = !1, t && ndpAttr.onChange && ndpAttr.onChange()
}

function BsAddDays(t, e) {
    var n = new NepaliDateConverter
    return n.add_bs_days(t, e)
}

function BsDatesDiff(t, e) {
    var n = new NepaliDateConverter
    return n.count_bs_days(t, e) + 2
}

function get2DigitNo(t) {
    return t = parseInt(t, 10), 10 > t ? "0" + t : "" + t
}

function getMonths() {
    var t = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
    return t
}

function getNepaliMonths() {
    var t = ["Baisakh", "Jestha", "Ashar", "Shrawan", "Bhadra", "Ashoj", "Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"]
    return t
}

function getNepaliDaysShort() {
    var t = ["आ", "सो", "मं", "बु", "बि", "शु", "श"]
    return t
}

function getNepaliMonthsInNepali() {
    return ["बैशाख", "जेठ", "अषाढ", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मङ्सिर", "पौष", "माघ", "फाल्गुन", "चैत्र"]
}

function getNepaliMonth(t) {
    t = parseInt(t, 10)
    var e = getNepaliMonthsInNepali()
    return e[t]
}

function getCurrentDayName() {
    var t = new Date,
        e = t.getDay(),
        n = Array(7)
    return n[0] = "Sunday", n[1] = "Monday", n[2] = "Tuesday", n[3] = "Wednesday", n[4] = "Thursday", n[5] = "Friday", n[6] = "Saturday", n[e]
}

function getDayFromDate(t) {
    var e = t.split("-"),
        n = e[2],
        a = e[1],
        s = e[0],
        r = new Date(s, a - 1, n),
        i = r.getDay(),
        d = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    return d[i]
}

function numberOfBsDays(t, e) {
    var n = new NepaliDateConverter
    return n.bs[t][e]
}

function numberOfDays(t, e) {
    var n = new Date(t, e, 0)
    return n.getDate()
}

function AD2BS(t) {
    var e = new NepaliDateConverter
    return e.ad2bs(getNepaliFormat(t))
}

function BS2AD(t) {
    var e = new NepaliDateConverter
    return e.bs2ad(getNepaliFormat(t))
}

function getNepaliDate() {
    var t = new NepaliDateConverter
    return t.ad2bs(getDateInNo("/"))
}

function getDateInWords() {
    var t = getMonths(),
        e = new Date,
        n = e.getDate(),
        a = e.getMonth() + 1,
        s = e.getYear(),
        r = 1e3 > s ? s + 1900 : s
    return n + " " + t[a] + ", " + r
}

function getDateInNo(t) {
    var e = new Date,
        n = e.getDate(),
        a = e.getMonth() + 1,
        s = e.getFullYear()
    return a + t + n + t + s
}

function getNepaliFormat(t) {
    var e = t.split("-"),
        n = e[2],
        a = e[1],
        s = e[0]
    return a + "/" + n + "/" + s
}

function getAdDateInWords(t) {
    var e = getMonths(),
        n = t.split("-"),
        a = n[2],
        s = n[1],
        r = n[0]
    return a + " " + e[s] + ", " + r
}

function getNepaliDateInWords(t) {
    var e = getNepaliMonths(),
        n = t.split("-"),
        a = n[2],
        s = n[1],
        r = n[0]
    return a + " " + e[s] + ", " + r
}

function getCurrentYear() {
    var t = new Date,
        e = t.getFullYear()
    return e
}

function getCurrentMonth() {
    var t = new Date,
        e = t.getMonth() + 1
    return e
}

function getCurrentDay() {
    var t = new Date,
        e = t.getDate()
    return e
}

function makeArray() {
    for (i = 0; i < makeArray.arguments.length; i++) this[i + 1] = makeArray.arguments[i]
}

function englishNo2Nep(t) {
    t = "" + t
    for (var e = "", n = 0; n < t.length; n++) e += convertNos(t[n])
    return e
}

function convertNos(t) {
    switch (t) {
        case "०":
            return 0
        case "१":
            return 1
        case "२":
            return 2
        case "३":
            return 3
        case "४":
            return 4
        case "५":
            return 5
        case "६":
            return 6
        case "७":
            return 7
        case "८":
            return 8
        case "९":
            return 9
        case "0":
            return "०"
        case "1":
            return "१"
        case "2":
            return "२"
        case "3":
            return "३"
        case "4":
            return "४"
        case "5":
            return "५"
        case "6":
            return "६"
        case "7":
            return "७"
        case "8":
            return "८"
        case "9":
            return "९"
    }
}

function NepaliDateConverter() {
    this.bs_date_eq = "09/17/2000", this.ad_date_eq = "01/01/1944", this.bs = [], this.bs[2e3] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2001] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2002] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2003] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2004] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2005] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2006] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2007] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2008] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], this.bs[2009] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2010] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2011] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2012] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], this.bs[2013] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2014] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2015] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2016] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], this.bs[2017] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2018] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2019] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2020] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2021] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2022] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], this.bs[2023] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2024] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2025] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2026] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2027] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2028] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2029] = [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], this.bs[2030] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2031] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2032] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2033] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2034] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2035] = [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], this.bs[2036] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2037] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2038] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2039] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], this.bs[2040] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2041] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2042] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2043] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], this.bs[2044] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2045] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2046] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2047] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2048] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2049] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], this.bs[2050] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2051] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2052] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2053] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], this.bs[2054] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2055] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2056] = [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30], this.bs[2057] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2058] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2059] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2060] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2061] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2062] = [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31], this.bs[2063] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2064] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2065] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2066] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31], this.bs[2067] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2068] = [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2069] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2070] = [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30], this.bs[2071] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2072] = [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30], this.bs[2073] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31], this.bs[2074] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2075] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2076] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], this.bs[2077] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31], this.bs[2078] = [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2079] = [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30], this.bs[2080] = [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30], this.bs[2081] = [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30], this.bs[2082] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], this.bs[2083] = [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30], this.bs[2084] = [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30], this.bs[2085] = [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30], this.bs[2086] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], this.bs[2087] = [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30], this.bs[2088] = [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30], this.bs[2089] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], this.bs[2090] = [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30], this.count_ad_days = count_ad_days, this.count_bs_days = count_bs_days, this.add_bs_days = add_bs_days, this.add_ad_days = add_ad_days, this.bs2ad = bs2ad, this.ad2bs = ad2bs
}

function count_ad_days(t, e) {
    var n = 864e5,
        a = t.split("/"),
        s = e.split("/")
    a[2] = +a[2], a[1] = +a[1], a[0] = +a[0], s[2] = +s[2], s[1] = +s[1], s[0] = +s[0]
    var r = new Date(a[2], a[0] - 1, a[1]),
        i = new Date(s[2], s[0] - 1, s[1]),
        d = Math.ceil((i.getTime() - r.getTime()) / n)
    return d
}

function count_bs_days(t, e) {
    var n = t.split("/"),
        a = e.split("/"),
        s = +n[2],
        r = +n[0],
        i = +n[1],
        d = +a[2],
        o = +a[0],
        h = +a[1],
        p = 0,
        l = 0
    for (l = s; d >= l; l++) p += arraySum(this.bs[l])
    for (l = 0; r > l; l++) p -= this.bs[s][l]
    for (p += this.bs[s][11], l = o - 1; 12 > l; l++) p -= this.bs[d][l]
    return p -= i + 1, p += h - 1
}

function add_ad_days(t, e) {
    var n = new Date(t)
    return n.setDate(n.getDate() + e), ad_month = n.getMonth() + 1, ad_day = n.getDate(), n.getFullYear() + "-" + (ad_month < 10 ? "0" + ad_month : ad_month) + "-" + (ad_day < 10 ? "0" + ad_day : ad_day)
}

function add_bs_days(t, e) {
    var n = t.split("/"),
        a = +n[2],
        s = +n[0],
        r = +n[1]
    for (r += e; r > this.bs[a][s - 1];) r -= this.bs[a][s - 1], s++, s > 12 && (s = 1, a++)
    return a + "-" + (10 > s ? "0" + s : s) + "-" + (10 > r ? "0" + r : r)
}

function bs2ad(t) {
    return days_count = this.count_bs_days(this.bs_date_eq, t), this.add_ad_days(this.ad_date_eq, days_count)
}

function ad2bs(t) {
    return days_count = this.count_ad_days(this.ad_date_eq, t), this.add_bs_days(this.bs_date_eq, days_count)
}
ndpAttr = {}, npdCalendarVisible = "", npdIgnoreMouseUp = !1, ndpData = [],
    function(t) {
        t.fn.nepaliDatePicker = function(e) {
            e = void 0 !== e ? e : {}, ndpAttr = e, this.each(function() {
                var n = t(this).attr("id")
                t(this).addClass("ndp-nepali-calendar"), ndpData[n] = e, ndpAttr.onFocus !== !1 && t(this).attr("onfocus", "showNdpCalendarBox('" + n + "')"), ndpAttr.ndpTriggerButton && t(this).after('<button type="button" class="ndp-click-trigger ' + (ndpAttr.ndpTriggerButtonClass ? ndpAttr.ndpTriggerButtonClass : "") + '" onclick="showNdpCalendarBox(&quot;' + n + '&quot;)">' + (ndpAttr.ndpTriggerButtonText ? ndpAttr.ndpTriggerButtonText : "Pick Date") + "</button>")
            }), t("body").append(getCalendarDivString(ndpAttr)), t(".ndp-nepali-calendar, #ndp-nepali-box").hover(function() {
                mouse_is_inside = !0
            }, function() {
                mouse_is_inside = !1
            }), t("html").mouseup(function(e) {
                t(e.target).is(".ndp-click-trigger") || npdCalendarVisible && !mouse_is_inside && hideCalendarBox(!1)
            })
        }
    }(jQuery)
var mouse_is_inside = !1
arraySum = function(t) {
    for (var e = 0, n = t.length; n; e += t[--n]);
    return e
}
style.min.css

.ndp-days th,.ndp-header{font-weight:700;text-align:center}div#ndp-nepali-box{font-family:'Trebuchet MS',Tahoma,Verdana,Arial,sans-serif;border:1px solid #A6C9E2;background-color:#FDFEFE;position:absolute;z-index:9999;padding:1px;margin-top:1px}div#npd-table-div{margin:0}div#npd-table-div table{border-spacing:2px;border-collapse:separate}div#ndp-nepali-box td.ndp-date{margin:1px;padding:1px 2px;border:1px solid #C5DBEC;background:url(images/ndp_date_bg.png) repeat-x #DFEFFC;color:#2E6E9E}div#ndp-nepali-box td.ndp-selected{border:1px solid #FAD42E;background:#FBEC88;color:#363636}div#ndp-nepali-box td.ndp-current{margin:1px;padding:1px 2px;border:1px solid #79B7E7;background:#F5F8F9}div#ndp-nepali-box td.ndp-current a{color:#E17009}div#ndp-nepali-box td.ndp-date a{display:block;color:#1C94C4;text-decoration:none;font-size:12px;width:20px}a.ndp-disabled{color:#ccc!important}div#ndp-nepali-box td.ndp-date:hover{border:1px solid #FED22F;opacity:.8}div#ndp-nepali-box td.ndp-date a:hover{color:#1C94C4}div#ndp-nepali-box table,div#ndp-nepali-box td,div#ndp-nepali-box tr{font-size:12px;height:19px;line-height:19px}.ndp-next,.ndp-prev{position:absolute;top:6px;width:1.3em;height:1.3em}div#ndp-nepali-box a{text-decoration:none}.ndp-header{border:1px solid #4297D7;background:url(images/ndp_bg_wave.png) 50% 50% repeat-x #5C9CCC;color:#fff;font-size:13px;line-height:20px;margin:2px}.ndp-prev{left:7px;background:url(images/ndp_buttons.png) no-repeat}.ndp-prev:hover{background:url(images/ndp_buttons.png) -16px 0 #D0E5F5}.ndp-next:hover{background:url(images/ndp_buttons.png) -48px 0 #D0E5F5}.ndp-next{right:7px;background:url(images/ndp_buttons.png) -32px 0 no-repeat}#currentMonth #npd-month-select,#currentMonth #npd-year-select{color:#000;font-size:12px;font-weight:400}.ndp-corner-all,.ndp-corner-left,.ndp-corner-tl,.ndp-corner-top{-moz-border-radius-topleft:5px;-webkit-border-top-left-radius:5px;-khtml-border-top-left-radius:5px;border-top-left-radius:5px}.ndp-corner-all,.ndp-corner-right,.ndp-corner-top,.ndp-corner-tr{-moz-border-radius-topright:5px;-webkit-border-top-right-radius:5px;-khtml-border-top-right-radius:5px;border-top-right-radius:5px}.ndp-corner-all,.ndp-corner-bl,.ndp-corner-bottom,.ndp-corner-left{-moz-border-radius-bottomleft:5px;-webkit-border-bottom-left-radius:5px;-khtml-border-bottom-left-radius:5px;border-bottom-left-radius:5px}.ndp-corner-all,.ndp-corner-bottom,.ndp-corner-br,.ndp-corner-right{-moz-border-radius-bottomright:5px;-webkit-border-bottom-right-radius:5px;-khtml-border-bottom-right-radius:5px;border-bottom-right-radius:5px}
<html>
<head>
  <title>Nepali Calendar</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  </head>
<body>
  <div class="container">
    <h3>Datepicker with button</h3>
    <input type="text" id="nepaliDate3" class="nepali-calendar" value=""/><br/><br/>
    <div id='calendar'>How to append calendar in this div without any event ??</div>
  </div>

<script>
  $(document).ready(function(){
    $('#nepaliDate3').nepaliDatePicker({
      onFocus: true,
      npdMonth: true,
      npdYear: true,
      ndpTriggerButton: true,
      ndpTriggerButtonText: 'Date',
      ndpTriggerButtonClass: 'btn btn-primary btn-sm'
    });
  });
</script>	
</body>
</html>

2 个答案:

答案 0 :(得分:0)

在Datepicker代码中编写此代码后,我希望它会起作用:

var calendar = $("input#nepaliDate3").html();
$("input#nepaliDate3").remove();
$("#calender").append(calendar);

答案 1 :(得分:0)

基于OP的评论。我对脚本进行了如下修改。

我添加了一个新属性inLine,以获取日历是否必须内联显示。

$('#calendar').nepaliDatePicker({
      onFocus: false,
      inLine:true, // Added new attribute
      npdMonth: true,
      npdYear: true,
      ndpTriggerButton: false,
      ndpTriggerButtonText: 'Date',
      ndpTriggerButtonClass: 'btn btn-primary btn-sm'
    });

,然后修改datepicker函数

    function(t) {
                t.fn.nepaliDatePicker = function(e) {
                    e = void 0 !== e ? e : {}, ndpAttr = e, this.each(function() {
                    console.log(ndpAttr.inLine);
                        var n = t(this).attr("id")
                        t(this).addClass("ndp-nepali-calendar"), ndpData[n] = e,
 ndpAttr.inLine && t(this).append(showNdpCalendarBox(n)) // newly added  - to show calendar inline
    , ndpAttr.onFocus !== !1 && t(this).attr("onfocus", "showNdpCalendarBox('" + n + "')"), ndpAttr.ndpTriggerButton && t(this).after('<button type="button" class="ndp-click-trigger ' + (ndpAttr.ndpTriggerButtonClass ? ndpAttr.ndpTriggerButtonClass : "") + '" onclick="showNdpCalendarBox(&quot;' + n + '&quot;)">' + (ndpAttr.ndpTriggerButtonText ? ndpAttr.ndpTriggerButtonText : "Pick Date") + "</button>")
                    }), t("body").append(getCalendarDivString(ndpAttr)), t(".ndp-nepali-calendar, #ndp-nepali-box").hover(function() {
                        mouse_is_inside = !0
                    }, function() {
                        mouse_is_inside = !1
                    }), t("html").mouseup(function(e) {
                        t(e.target).is(".ndp-click-trigger") || npdCalendarVisible && !mouse_is_inside && hideCalendarBox(!1)
                    })
                }
            }(jQuery)

我没有检查其他功能。希望这会有所帮助。

DEMO HERE