php中怎么插入JS事件,如循环数据库表内字段,点击a标签链接,弹出提示框,并显示数据库的字段 100
functionresult2Arr($result){while($result_row=mysql_fetch_assoc($result)){$arr[]=$res...
function result2Arr($result){
while($result_row=mysql_fetch_assoc($result)){
$arr[] = $result_row;
}
return $arr;
}
$arr = result2Arr($result);
foreach($arr as $key=>$value){
echo "<tr> ";
echo "<td width='100px'>".$value['id']."</td>";
echo "<td width='200px'height='35px'>".$value['lianjie']."</td>";
echo "<td ><script<a href="#" onclick="fun1()">你有一个礼物</a>";
echo "function fun1(){alert("$value['lianjie']") } </script>";
echo "</td >";
echo "</tr>"; 展开
while($result_row=mysql_fetch_assoc($result)){
$arr[] = $result_row;
}
return $arr;
}
$arr = result2Arr($result);
foreach($arr as $key=>$value){
echo "<tr> ";
echo "<td width='100px'>".$value['id']."</td>";
echo "<td width='200px'height='35px'>".$value['lianjie']."</td>";
echo "<td ><script<a href="#" onclick="fun1()">你有一个礼物</a>";
echo "function fun1(){alert("$value['lianjie']") } </script>";
echo "</td >";
echo "</tr>"; 展开
展开全部
$str = "";
foreach($arr as $key=>$value){
$str .= "<tr> ";
$str .= "<td width='100px'>".$value['id']."</td>";
$str .= "<租茄游td width='200px'height='35px' id='lianjie'>".$value['lianjie']."</td>";
$str .= "<td ><a href="弊销#" onclick="fun1()">你有一个礼物</a>";
$str .= "</td >";
$str .= "</tr>"纳含;
}
$str .= "<script>function fun1(){
var text = document.getElementById('lianjie');alert(text) } </script>";
echo $str;
fun1有一个就可以了,没必要在循环体内
foreach($arr as $key=>$value){
$str .= "<tr> ";
$str .= "<td width='100px'>".$value['id']."</td>";
$str .= "<租茄游td width='200px'height='35px' id='lianjie'>".$value['lianjie']."</td>";
$str .= "<td ><a href="弊销#" onclick="fun1()">你有一个礼物</a>";
$str .= "</td >";
$str .= "</tr>"纳含;
}
$str .= "<script>function fun1(){
var text = document.getElementById('lianjie');alert(text) } </script>";
echo $str;
fun1有一个就可以了,没必要在循环体内
追问
$str .= "你有一个礼物"; 这行会显示语法错误
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询