我该怎么做呢?
<a href="#" onClick="javascript.functiontoget$date();">'.$date.'</a>
$date值在while循环内
while($row = mysqli_fetch_array($query)){
$date = $row['Date'];
echo '<tr class="normalRow"><td><a href="#" onClick="javascript.functiontoget$date();">$date</a></td></tr>;'
}
变量不能在单引号字符串中展开,只能在双引号字符串中展开。你需要使用串联。
echo '<tr class="normalRow"><td><a href="#" onClick="javascript.functiontoget$date();">' . $date . '</a></td></tr>;'
所以要么在你调用的方法中设置日期
onclick="foo('thedate')"
或引用被点击的元素并读取文本
onclick="foo(this)"
和
function foo(elem) {
alert(elem.textContent);
}
function foo1(str) {
alert(str);
}
function foo2(elem) {
alert(elem.textContent);
}
<table>
<tbody>
<tr>
<td><a href="#" onclick="foo1('hello')">hello</a>
</td>
</tr>
<tr>
<td><a href="#" onclick="foo2(this)">hello</a>
</td>
</tr>
</tbody>
</table>