jquery load append datepicker函数 [英] jquery load append datepicker function
问题描述
我有以下函数生成编号的输入字段,其中包含当前时间戳的 id
s和 name
s 被创造了我正在尝试为每个创建的日期戳附加一个datepicker,因此唯一/ timestamp id的。
I have the following function that produces numbered input fields with id
s and name
s of the current timestamp they're were created. I'm trying to attach a datepicker to each one created, hence the unique/timestamp id's.
有人可以建议一个方法来做这个吗?
Can anybody suggest a way for me to go about doing this?
我相信datepicker函数需要在每个创建的输入字段下生成,但我不知道如何使用JavaScript生成JavaScript函数。我想也许我可以使用jQuery的 load()
函数,并调用一个生成一个独特的函数并将其加载到一个div的PHP脚本。这是解决这个问题的最好办法吗?谢谢!
I believe the datepicker function needs to be produced under each input field created but I don't know how to produce a JavaScript function with JavaScript. I'm thinking maybe I can use jQuery's load()
function and call a PHP script that produces a unique function and loads it into a div. Is that the best way to tackle this? Thanks!
<script>
var number = 0;
var num;
$('#add_date').click(function(event) {
number++;
var d=new Date();
var year = d.getFullYear();
var day = d.getDate();
var month = d.getMonth() + 1;
if (month<10){var month = "0"+month;}
if (day<10){var day = "0"+day;}
var fullyear = month+"/"+day+"/"+year;
num = event.timeStamp
$('#box').append( number+". <input type='text' id='" + num + "' name='" + num + "' value='"+ fullyear + "' size='10'/><br><br>");
var idtag = "#"+num;
});
</script>
推荐答案
为什么不创建日期戳输入?
Why not just set up the datepicker when you create the input?
var picker = $("<input/>", {
type: 'text',
id: num,
name: num,
value: fullyear
}).datepicker();
$('#box').append(number).append(picker);
此外,您应该使id值看起来像有效的标识符,而不是纯数字。
Also you should make "id" values that look like valid identifiers instead of plain numbers.
这篇关于jquery load append datepicker函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!