我有以下几行代码:

jQuery的

$(".datepicker").datepicker({
    showOn: "button",
    buttonImage: "images/calendar.gif",
    buttonImageOnly: true,
    dateFormat: "MM d, yy",
    changeMonth: true,
    changeYear: true
});


Java脚本

var element1 = document.createElement("input");
element1.type = "text";
element1.setAttribute("class", "datepicker");


假设要在JavaScript中创建的元素必须是datepicker,因此我将其类设置为jQuery代码中定义的“ datepicker”。但是这东西行不通。

任何可能的解决方案?设置在css中定义的类对我有用,但是这可以。

最佳答案

只要在您的元素创建并附加到DOM之后运行jQuery代码,您所做的工作就应该可以正常工作。

10-05 20:54
查看更多