gpt4 book ai didi

php - 将 PHP 数组传递给 JavaScript 函数不起作用

转载 作者:行者123 更新时间:2023-11-28 02:23:56 27 4
gpt4 key购买 nike

我正在尝试使用 onClick 功能将 php 数组传递给 JavaScript 函数 FindCheckBoxes(Test)。但这段代码似乎不起作用。似乎 JSON_ENCODING 不起作用。

如何将 $array 变量传递给 JavaScript 函数。我已经在互联网上搜索过但无法让它工作。也就是说,警报不输出任何内容(空白)。我希望 '$array' 参数在那里这是我的代码:

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

<head>
<meta charset="UTF-8" />
<!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> -->
<title>Login and Registration Form with HTML5 and CSS3</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Facebook Timeline" />
<meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/style1.css" />
<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
<?php
$array =array();
array_push($array,"aa");
?>
function comment(){
var jFirst = document.getElementById("usernamesignup").value;
alert("Your name is: "+ jFirst);
}
function findCheckedBoxes(test) {
alert("here");
var select_array= new Array();
alert(test);
var AllBoxes = $(".pp");
for(i=0;i<AllBoxes.length;i++)
{
if(AllBoxes[i].checked)
{

select_array.push(foo[i]);
}
}
alert(select_array);
return true;
}
</script>

</head>
<body>
<?php
//PostID = 0 means its not a constraint
function comment($pauthor, $author, $substr, $start, $postid, $end) {
$q = "select * from Comment where Author like '".$author."%' and Text like '%".$substr."%' and Time >= '".$start."' and Time <= '".$end."' and (PostID = ".strval($postid)." or ".strval($postid)." = 0) and PostID in (select PostID from Post where Author like '".$pauthor."%')";

return $q;

}

function user($user, $pre, $post, $sepr) {
if($user == 1) return $pre."1".$post.$sepr.$pre."2".$post.$sepr.$pre."3".$post;
if($user == 2) return $pre."2".$post.$sepr.$pre."3".$post;
//if($user == 3)
return $pre."3".$post;
}

function comb($q1, $q2, $q3) {
$str = "'000'";
for($i = $q1; $i <= 3; $i++) {
for($j = $q2; $j <= 3; $j++) {
for($k = $q3; $k <= 3; $k++) {
$str = $str.", '".strval($i).strval($j).strval($k)."'";
}
}
}
return $str;
}

function perm($g1, $g2, $g3,$union,$user) {
if($union) {
if($g1 && $g2 && $g3) //return "Permission_bits like %3% or Permission_bits like %2% or Permission_bits like %1%";
return user($user, "Permission_bits like '%", "%'", " or ");
if($g1 && $g2) return user($user, "Permission_bits like '", "__'", " or ").user($user, "Permission_bits like '_", "_'", " or ");
if($g2 && $g3) return user($user, "Permission_bits like '__", "'", " or ").user($user, "Permission_bits like '_", "_'", " or ");
if($g1 && $g3) return user($user, "Permission_bits like '", "__'", " or ").user($user, "Permission_bits like '__", "'", " or ");
if($g1) return user($user, "Permission_bits like '", "__'", " or ");
if($g2) return user($user, "Permission_bits like '_", "_'", " or ");
if($g3) return user($user, "Permission_bits like '__", "'", " or ");
return "Permission_bits = '000'";
} else {
if($g1 && $g2 && $g3) return "Permission_bits in (".comb($user, $user, $user).")";
if($g1 && $g2) return "Permission_bits in (".comb($user, $user, 0).")";
if($g2 && $g3) return "Permission_bits in (".comb(0, $user, $user).")";
if($g1 && $g3) return "Permission_bits in (".comb($user, 0, $user).")";
if($g1) return "Permission_bits in (".comb($user, 0, 0).")";
if($g2) return "Permission_bits in (".comb(0, $user, 0).")";
if($g3) return "Permission_bits in (".comb(0, 0, $user).")";
return "Permission_bits = '000'";
}
}
?>
<?php
$author=$_REQUEST['author'];
$pauthor=$_REQUEST['post_author'];
$text=$_REQUEST['text'];
$start=$_REQUEST['start'];
$end=$_REQUEST['end'];
?>



<div class="container">
<!-- Codrops top bar -->
<div class="codrops-top">

<span class="right">

</span>
<div class="clr"></div>
</div><!--/ Codrops top bar -->
<header>
<h1>FACEBOOK TIMELINE</h1>

</header>
<section>
<div id="container_demo" >
<!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form action="comments.php" autocomplete="on">
<h1>COMMENTS</h1>
<br>
<br>

<TABLE>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<td>
<img src="comments.jpg" align="center" width=400>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

</td>



<td>

<FORM id="FORM" action="comments.php" method="post">
<INPUT TYPE="submit" id="1" VALUE="START A NEW SEARCH HERE " >
</FORM>
</td>
</TABLE>
<br>
<br>
<TABLE BORDER="0" WIDTH=200px ALIGN=CENTER>
<tr>
<h1>YOUR RESULTS</h1>
<INPUT TYPE="button" onClick="findCheckedBoxes('<?php json_encode($array); ?>')" VALUE="CHANGE PERMISSION TO GROUP MEMBERS ONLY" />
<INPUT TYPE="button" onclick="findCheckedBoxes()" VALUE="CHANGE PERMISSION TO YOUR FRIENDS ONLY"/>
<INPUT TYPE="button" onclick="findCheckedBoxes()" VALUE="CHANGE PERMISSION TO EVERYBODY" />
<?php
//echo '<FORM id="MYFORM0" onsubmit="return findCheckedBoxes()" >

//</FORM>.<br>.<br>';
// Connects to your Database
mysql_connect("10.142.233.33", "root", "limiwisn") or die(mysql_error());
//mysql_connect("", "root", "guitar") or die(mysql_error());
$count=0;
mysql_select_db("Ass3") or die(mysql_error());
$datai = mysql_query(comment($pauthor, $author, $text, $start, 0, $end))
or die(mysql_error());
while($infoi = mysql_fetch_array( $datai ))
{
$count = $count + 1;
}
echo '<tr><td><font size=5>';
echo "Total number of Comments ->".strval($count)."<br><br>";
echo '</tr></td></font>';
echo "<br>";
mysql_select_db("Ass3") or die(mysql_error());
$datai = mysql_query(comment($pauthor, $author, $text, $start, 0, $end))
or die(mysql_error());
echo '<tr><td><font size=4>';

while($infoi = mysql_fetch_array( $datai ))
{
echo $infoi['CommentID']."<br>";
echo '<input type="checkbox" class="pp" name="sdfsdg" value="my_checkbox"/>'.'<br>';
echo $infoi['Author']."<br>";
echo $infoi['Text']."<br>";
echo $infoi['Time']."<br><br><br>";
array_push($array,$infoi['CommentID']);
}
echo "<br>";
echo '</td></tr></font>';
echo '</table>';
print_r ($array);
?>
<br>
<br>





</form>
</div>



</div>
</div>
</section>
</div>
</body>
</html>

最佳答案

json_encode只是返回值 - 你仍然需要告诉 php 如何处理它,即。替换这个:

<?php json_encode($array); ?>

这样:

<?php echo json_encode($array); ?>

可能是盯着屏幕时间太长的情况吗?

关于php - 将 PHP 数组传递给 JavaScript 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15254453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com