我如何使用输入框ID从PHP到JavaScript? [英] How can I use input Box ID from PHP to JavaScript?
问题描述
我的JavaScript函数运行正常,但是我有问题从PHP输入框中获取不同的id。
$ b
JavaScript
window.onload = function()
{
new JsDatePick({
useMode:2,
target:inputField1, //这里我想通过不同的ID ex。inputField1+i
dateFormat:%Y-%M-%d,
年限范围:[1978,2120],
limitToToday:false,
cellColorScheme:beige,
imgPath:main / img /,
weekStartDay:1
});
循环的PHP输入框
< div class =start_date>
< strong>< label for =start_date>开始日期< / label>< / strong>
< br />< br /> ($ k = 1; $ k <= $ textboxindex; $ k ++)
{
echo< input type = \text \\ b
<?php
\\class ='textboxsize'id = \inputField1 \name = \start_date [] \value = \$ start_date \/>;
回声< br />;
}
?>
< / div>
工作正常,但我希望在JavaScript函数中使用不同的ID名称。任何想法?
这是行不通的...
echo< input type = \text \class ='textboxsize'id = \inputField + $ k\name = \start_date [] \value = \$ start_date \ />;
任何帮助将不胜感激。
这很可能是使用 JsDatePick
小部件。它的 target
参数需要一个元素的一个ID,因此你必须将JS代码封装在一个循环中,并为每个字段ID启动一个单独的Widget实例。
假设您的输入字段索引以1开头:
窗口。 onload = function()
{
var i =<?= $ totalNumberOfInputs;?> (j = 1; j <= i; j ++){
new JsDatePick({
useMode:2,
target:inputField+ j,
) //这里我想通过不同的ID例如inputField1+ j
dateFormat:%Y-%M-%d,
年限范围:[1978,2120],
limitToToday:false,
cellColorScheme:beige,
imgPath:main / img /,
weekStartDay:1
});
}
}
您不需要将+号连接双引号内的字符串(顺便说一句,这是点)。
My JavaScript function works fine, but I have problems getting different ids from the PHP input box.
JavaScript
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
});
My PHP input box for loop
<div class = "start_date" >
<strong><label for="start_date">Start Date</label></strong>
<br/><br/>
<?php
for($k=1;$k<=$textboxindex;$k++)
{
echo "<input type=\"text\" class='textboxsize' id= \"inputField1\" name=\"start_date[]\" value=\"$start_date\" />";
echo "<br/>";
}
?>
</div>
It works fine, but I would like to have different ID names to use in the JavaScript function. Any ideas?
This doesn't work...
echo "<input type=\"text\" class='textboxsize' id= \"inputField+$k\" name=\"start_date[]\" value=\"$start_date\" />";
Any help will be appreciated.
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 = <?=$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
});
}
}
You don't need to put the + sign to concatenate strings within double quotes (it's dot, by the way).
这篇关于我如何使用输入框ID从PHP到JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!