How can I use input Box ID from PHP to JavaScript?

后端 未结 3 2097
滥情空心
滥情空心 2021-01-29 03:27

My JavaScript function works fine, but I have problems getting different ids from the PHP input box.

JavaScript

window.onload = function()
{   
new JsD         


        
3条回答
  •  旧巷少年郎
    2021-01-29 03:37

    It's most likely with JsDatePick widget. Its target parameter takes a single ID of an element, therefore you'd have to wrap the JS code in a loop and initiate a separate instance of the widget for each field ID.

    Assuming your input field indexing starts with 1:

    window.onload = function()
    {   
        var i = 
    
        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
            });
        }
    }
    

    You don't need to put the + sign to concatenate strings within double quotes (it's dot, by the way).

提交回复
热议问题