Javascript - 将动态递归 PHP 值作为 javascript 函数传递
Javascript - passing dynamic recursive PHP value as javascript function
javascript 的新手。我在 PHP 中有一个 while 循环,看起来像这样
while ($row_voucher=mysql_fetch_row($risultato_query_voucher)) { //INFO poche righe sotto, date_format da solo non funziona
echo "<tr>\n
<td id=" . $row_voucher[3] ."><input type='checkbox' value='" . $row_voucher[3] . "' onchange='ControllaCodice(this)' id='" . $row_voucher[6] . "'></td>\n
<td>" . $row_voucher[2] . "</td>\n
<td>" . $row_voucher[3] . "</td>\n
<td>" . date_format( new DateTime($row_voucher[4]), 'd/m/Y' ). "</td>\n
<td>" . date_format( new DateTime($row_voucher[5]), 'd/m/Y' ). "</td>\n
<td>" . $row_voucher[6] . "</td>\n
</tr>\n";
}
我需要做的是,当您单击复选框时,获取第一个输入类型的值并将其添加。由于它是一个 while 循环,这将生成一个 table,其中包含许多复选框,每个复选框具有不同的值。因此,如果您例如选中 3 个复选框,我写的 javascript 应该采用 3 个值并添加它,然后打印它。
如果可能的话,我还需要在检查时添加值并在取消检查时减去它。
这是无效的 javascript 代码:
<script type='text/javascript'>
function ControllaCodice(this.value){
window.alert(this.value);
}
</script>";
提前致谢。
您没有将 this.value
传递给接受一个属性的函数,而是 this
。变量的名称无关紧要,重要的是内容。虽然,您不能在函数中接受 this
,它是一个保留变量。
此外,使用 window.alert
不是必须的,只需使用 alert
.
即可
所以,代码是:
... onchange = "ControllaCodice(this)" ...
function ControllaCodice(c){
alert(c.value);
}
this.value
不是有效的参数名称,使用函数所有者作为参数不是一个好主意。相反,让它成为一个正常的参数。
function ControllaCodice(input) {
alert(input.value);
}
javascript 的新手。我在 PHP 中有一个 while 循环,看起来像这样
while ($row_voucher=mysql_fetch_row($risultato_query_voucher)) { //INFO poche righe sotto, date_format da solo non funziona
echo "<tr>\n
<td id=" . $row_voucher[3] ."><input type='checkbox' value='" . $row_voucher[3] . "' onchange='ControllaCodice(this)' id='" . $row_voucher[6] . "'></td>\n
<td>" . $row_voucher[2] . "</td>\n
<td>" . $row_voucher[3] . "</td>\n
<td>" . date_format( new DateTime($row_voucher[4]), 'd/m/Y' ). "</td>\n
<td>" . date_format( new DateTime($row_voucher[5]), 'd/m/Y' ). "</td>\n
<td>" . $row_voucher[6] . "</td>\n
</tr>\n";
}
我需要做的是,当您单击复选框时,获取第一个输入类型的值并将其添加。由于它是一个 while 循环,这将生成一个 table,其中包含许多复选框,每个复选框具有不同的值。因此,如果您例如选中 3 个复选框,我写的 javascript 应该采用 3 个值并添加它,然后打印它。 如果可能的话,我还需要在检查时添加值并在取消检查时减去它。
这是无效的 javascript 代码:
<script type='text/javascript'>
function ControllaCodice(this.value){
window.alert(this.value);
}
</script>";
提前致谢。
您没有将 this.value
传递给接受一个属性的函数,而是 this
。变量的名称无关紧要,重要的是内容。虽然,您不能在函数中接受 this
,它是一个保留变量。
此外,使用 window.alert
不是必须的,只需使用 alert
.
所以,代码是:
... onchange = "ControllaCodice(this)" ...
function ControllaCodice(c){
alert(c.value);
}
this.value
不是有效的参数名称,使用函数所有者作为参数不是一个好主意。相反,让它成为一个正常的参数。
function ControllaCodice(input) {
alert(input.value);
}