php - onClick 的 javascript 没有执行?

标签 php javascript html

好吧,也许我必须把我所有的代码:

<?php
include('header_application.php');
$obj_clean->check_user();
$limit = 10;
if(!isset($_GET['page']))
  $page = 1;
else
$page = $_GET['page'];

$from = (($page * $limit) - $limit);
$msg = "";
if (isset($_GET['unblock']))
{
  $code = $obj_clean->unblockUser($_GET['unblock'],$_GET['code']);
  if ($code == "error")
  {
     $msg = "Could not delete message!";
  }
  else
  {
    $msg = "You have unblocked ".$code;
  }
}

//Get dynamic data required for this page from the database
$users = $obj_clean->getContacts($_SESSION['user_id'], $from, $limit);
$rows = $obj_clean->getContactsCount($_SESSION['user_id']);
include ("header.php");
?>
<div class="innerContainer">
<head>
<script type="text/JavaScript">
function yesnolist(val)
{
 var e = confirm('Do you want to send a free chat request?');
 if (e == true)
 {
    window.location.href = "http://www-rainbowcode-mobi/confirmfreechat.php";
    //window.location('http://www-rainbowcode-mobi/confirmfreechat.php');
    return true;
 }
  else
    return false;
 }     
</script>  
</head>
<span class="headings2">CONTACTS</span>
<?php if (isset($msg) && !empty($msg)) echo "<br/><font color='red'>".$msg."</font>"; ?>
<br/><br/>
<?php
if (count($users) > 0)
{
    echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
    foreach ($users as $user)
    {
        //Breaks the unique code into 3 parts so that the numeric part can be a different colour
        $codeLength = strlen($user['unique_code']);
        $firstPartLength = $codeLength - 5;
        $uniqueCode3 = substr($user['unique_code'], -2);
        $uniqueCode2 = substr($user['unique_code'], -5, 3);
        $uniqueCode1 = substr($user['unique_code'], 0, $firstPartLength);
        echo '<tr>';
        echo '<td>';
        echo '<a class="charcoal_link" style="line-height: 20px;" href="'.ADDRESS.'view_profile.php?id='.$user['profile_id_contact'].'">'.$uniqueCode1.'<span class="pink_text">'.$uniqueCode2.'</span>'.$uniqueCode3.'</a>';
        $requestor_id = $_SESSION['user_id'];
        $profile_id = $user['profile_id_contact'];
        $rel1 = $obj_clean->hasRelation($requestor_id,$profile_id);
        $rel2 = $obj_clean->hasRelation($profile_id,$requestor_id);
        if($rel1 && $rel2) 
        {
          echo "&nbsp;&nbsp;";
          //echo '<a href="confirmfreechat.php?id='.$profile_id.'" onClick="yesnolist()">Free Chat</a>';
          echo '<a href="#" onClick="yesnolist(); return false;">Free Chat</a>';
        }
        echo "</td>";
        echo "</tr>";
    }
    echo "</table>";
}
else
{
    echo "You have no contacts yet";
}
?>
</div>
<?php include("footer.php"); ?>

希望这会有所帮助

最佳答案

<a href="" onClick="yesnolist()">Free Chat</a>

should be:

<a href="#" onClick="yesnolist(); return false;">Free Chat</a>

关于php - onClick 的 javascript 没有执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5881444/

相关文章:

javascript - 缓冲区使用说明

php - 如何使用php在父目录中创建子目录?

php - 我想比较 PHP 中的两个数组

javascript - 从本地文件在 Mapbox 中加载带有杂食动物的 csv

javascript - 从html返回值的angularjs调用函数

javascript - ionic 和 Angular : Toggle CSS throughout the entire app?

html - 使用 Bootstrap 进行页脚自适应定位

php - 没有 SSH 访问权限的 Symfony 2

php - 在 Docker 中从 php 连接到 mysql

javascript - 在运行时在 Three.js 中更改从 blender 导入的模型的面部颜色