[英]passing multiple parameter in an onclick event
I am having an issue passing multiple variables. 我在传递多个变量时遇到问题。 Since I am building my table on the fly I am using double quotes to store the HTML.
由于我正在动态建立表格,因此我使用双引号来存储HTML。 This seems to be causing an issue on how to build the click event.
这似乎引起了有关如何构建click事件的问题。 While I can get this to function to some degree some of the values being passed have spaces since the column is a note or description that has white spaces.
虽然我可以使它在某种程度上起作用,但是由于列是带空格的注释或说明,因此某些传递的值带有空格。 I have tried everything I can think of.
我已经尝试了所有我能想到的。
$sql="SELECT date, type, description, note, nextdue, alert, id FROM medical
where dogid=$id";
$healthDetails = "<table border='1'>";
$healthDetails .= "<tr>";
$healthDetails .= "<td>Date</td>";
$healthDetails .= "<td>Type</td>";
$healthDetails .= "<td>Description</td>";
$healthDetails .= "<td>Note</td>";
$healthDetails .= "<td>Next Due</td>";
$healthDetails .= "<td>Alert</td>";
$healthDetails .= '<td>Action</td>';
foreach( $db->query($sql) as $data ) {
$healthDetails .= "<tr>";
$healthDetails .= "<td> $data[0] </td><td> $data[1] </td><td> $data[2] </td><td> $data[3] </td><td> $data[4] </td><td> $data[5] </td>";
$healthDetails .= "<td><a href=# onClick=editHealth('$data[0]','$data[1]','$data[2]','$data[6]'); > Edit</a> | <a href=''>Delete </a></td>";
$healthDetails .= "</tr>"; }
$healthDetails .= "</table>";
echo $healthDetails;
I have tried and had luck with \\". This allows me to pass white spaces but will only let me pass one value " 我已经尝试过并祝您好运\\“。这允许我传递空格,但只会让我传递一个值”
$healthDetails .= "<td><a href=# onClick='editHealth(\"$data[0]\",\"$data[1]\")'> Edit</a> | <a href=#>Delete </a></td>";
I have tried this as well but white spaces wont pass. 我也尝试过,但是空格不会通过。
$healthDetails .= <td><a href=# onClick='editHealth(\''$data[0]'\',\''$data[1]'\')'> Edit</a> | <a href=#>Delete </a></td>
Guessing that the entire issue is that I can't double quote the "" the onClick event 猜测整个问题是我不能在onClick事件中加双引号“”
$healthDetails .= <td><a href=# onClick="editHealth(\''$data[0]'\',\''$data[1]'\')"> Edit</a> | <a href=#>Delete </a></td>
我更改了方法并移至JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.