-1
window.onload = function()
{   
new JsDatePick({
useMode:2,
target:"inputField1", //HERE I WOULD LIKE TO PASS DIFFERENT ID ex. "inputField1"+ "i"
dateFormat:"%Y-%M-%d",
yearsRange:[1978,2120],
limitToToday:false,
cellColorScheme:"beige",
imgPath:"main/img/",
weekStartDay:1
});
};

在 inputField1 的目标替换中,我想要 inputField1、inputField2、inputField3 等。

4

3 回答 3

1
for(i=0;i<5;i++) {
    temp = "inputField"+i;
    window.onload = function() {   
        new JsDatePick({
            useMode: 2,
            target: temp,
            dateFormat: "%Y-%M-%d",
            yearsRange: [1978,2120],
            limitToToday: false,
            cellColorScheme: "beige",
            imgPath: "main/img/",
            weekStartDay: 1
        });
    };
}
于 2012-10-30T18:51:35.373 回答
0
window.onload = function()
{   
var i = <?=$totalNumberOfInputs;?>

for(j=1;j<=i;j++) {  
    new JsDatePick({
        useMode:2,
        target:"inputField" + j, //HERE I WOULD LIKE TO PASS DIFFERENT ID ex. "inputField1" + j
        dateFormat:"%Y-%M-%d",
        yearsRange:[1978,2120],
        limitToToday:false,
        cellColorScheme:"beige",
        imgPath:"main/img/",
        weekStartDay:1
    });
}

}

这是我另一个问题的答案 谢谢

于 2012-10-30T20:39:23.390 回答
0

为输入字段使用一个类,如 class="inputfield" 并使用循环创建 html 然后在 javascript 中。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery_urdu_editor/jquery.js" type="application/javascript"></script>
<link rel="stylesheet" type="text/css" media="all" href="jsdatepick-calendar/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsdatepick-calendar/jsDatePick.min.1.3.js"></script>
<script type="application/javascript">
 window.onload = function()
    {   
      $('.inputfield').each(function() {
         var thisId = $(this).attr('id');
            //document.write(thisId.'<br />');
         new JsDatePick({
             useMode:2,
             target:thisId,    // putting the id of this element.                    
             dateFormat:"%Y-%M-%d",
             yearsRange:[1978,2120],
             limitToToday:false,
             cellColorScheme:"beige",
             imgPath:"main/img/",
             weekStartDay:1
        });
    });
   };
</script>
</head>

<body>
<?php
    for($i=1;$i<=6;$i++){
        echo '<input type="text" name="textfield'.$i.'" class="inputfield" id="textfield'.$i.'" value="" ><br />';

    }
?>
</body>
</html>

在 javascript 代码中,我们获取元素的 ID 及其类,然后将该 ID 放入日历代码中。因此它适用于具有该类的任意数量的输入字段。希望它可以帮助你。

于 2012-10-30T18:54:32.423 回答