gpt4 book ai didi

jquery - 在动态表上使用 Jquery 添加日历日期选择器

转载 作者:行者123 更新时间:2023-12-01 08:27:33 26 4
gpt4 key购买 nike

我试图在创建时将 Jquery 日历选择器添加到文本框,但我找不到如何操作。

当我按下按钮时,它将创建一个表格,我想要附加 Jquery 日历选择器的元素是:

var txtDate = createTextInput(i, "txtDate", 8, 10);
txtDate.className = "datepicker";
this.newcells[i].appendChild(txtDate);

我尝试在末尾添加:

txtDate.datepicker();

但是不起作用。有人可以帮忙吗?

谢谢。

注意:CreateTextInput 是:

function createTextInput(i, strName, size, maxLength) {
var input = document.createElement('<input>');
input.type = "text";
input.name = strName;
input.id = strName + i;
input.size = size;
input.maxLength = maxLength;

return input;
}

最佳答案

使用

$("#txtDate").datepicker();

而不是

txtDate.datepicker();

您可以轻松地使用 jQuery 创建元素。类似的东西

$("<input type='text' />").attr("id", '').appendTo("yourelement");

您可以在 jQuery 中像这样重写 createtextinput 函数

function createTextInput(i, strName, size, maxLength) {
return $("<input />".attr({
type: 'text',
name: strName,
id: strName + i,
size: size,
maxLength: maxLength
});
}

如果您返回 jQuery 对象,那么您可以直接调用 datepicker(),例如

txtDate.datepicker();

关于jquery - 在动态表上使用 Jquery 添加日历日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2628548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com