在onClick函数中传递php变量 [英] passing php variable in onClick function
问题描述
我想在onClick函数中传递php变量值。
当我通过php变量时,在UI中,我获取变量本身,而不是我需要变量中的值。
下面是代码片段,请帮助我。
<?php
print'< td>';
$ node = $ name-> item(0) - > nodeValue;
$ insert =cubicle。$ node< br>;
Echo'< a href =#onClick = showDetails($ node);>'。 $ insert。'< / a> ;
print'< / td>';
?>
变量解析只能在双引号字符串 。您可以使用字符串连接,或者我发现它更具可读性, printf
:
最好的办法是不要 echo
HTML,但要在HTML中嵌入PHP:
<?php
$ node = $ name-> ;项(0) - >的nodeValue;
$ insert =cubicle。 $节点;
?>
< td>
< a href =#onClick =showDetails('<?php echo $ node;?>');>
<?php echo $ insert; ?> < br />
< / a>
< / td>
您不得不少思考引号,并且调试HTML也更容易。
$ b $
注意: 如果 $ node
代表一个数字,需要围绕论点引用标记。
I want to pass the php variable value in onClick function. When i pass the php variable, in the UI i am getting the variable itself instead I need the value in the variable.
Below is code snippet, please help me.
<?php
print '<td>';
$node = $name->item(0)->nodeValue;
$insert= "cubicle"."$node<br>";
Echo '<a href= "#" onClick= showDetails("$node");>'. $insert .'</a> ';
print '</td>';
?>
Variable parsing is only done in double quoted strings. You can use string concatenation or, what I find more readable, printf
[docs]:
printf('<a href= "#" onClick="showDetails(\'%s\');">%s</a> ', $node, $insert);
The best way would be to not echo
HTML at all, but to embed PHP in HTML:
<?php
$node = $name->item(0)->nodeValue;
$insert = "cubicle" . $node;
?>
<td>
<a href= "#" onClick="showDetails('<?php echo $node;?>');">
<?php echo $insert; ?> <br />
</a>
</td>
You have to think less about quotes and debugging your HTML is easier too.
Note: If $node
is representing a number, you don't need quotations marks around the argument.
这篇关于在onClick函数中传递php变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!