简体   繁体   中英

how to call this datepicker function while each row of table data is having the same class='datapicker'?

嗨,我有一个表,其中有用于datepicker的javascript函数,在此表中还具有添加和删除行的功能。因此,一旦创建新行,它将具有与上一行相同的ID。为表的每一行调用以下函数。但是约束是表数据将具有相同的id,name和class。此函数仅适用于第一行,而不适用于第二行。

By WWW standards, no two objects in a dom should have same id. So may be you can edit the javascript code that adds/delete rows to have an iterant appended to the id. Meanwhile you could also use data-* attributes. Read more about data-* attribs . Writing this as an answer as its difficult to give you links in comment.

All you need to do is, call datepicker after adding the new row also.

$tr.after($clone);
$("input.add").live('click', function() {        
    var $tr = $(this).closest('tr');
    var $clone = $tr.clone();

    // blah blah

    $tr.after($clone);
    $clone.find('input).datepicker({
             changeMonth: true,
             changeYear: true,
             showOn: 'button',
             buttonImage: 'jquery/images/calendar.gif',
             buttonImageOnly: true
           });
});

Also - a word of caution: Use on instead of live . live is deprecated in newer versions of jquery.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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