[英]Uncaught SyntaxError: Unexpected identifier
<link type='text/css' rel='stylesheet' href='./css/style.css'>
<link type='text/css' rel='stylesheet' href='css/dataTable.css'>
<?php
include("config.php");
include("meniu.php");
include("meniuV.php");
echo "<script type='text/javascript' charset='utf8' src='//code.jquery.com/jquery-1.10.2.min.js'></script>";
echo "<script type='text/javascript' charset='utf8' src='//cdn.datatables.net/1.10.4/js/jquery.dataTables.js'></script>";
session_start();
?>
<div id="bilet" class="BiletCSS">
</div>
<?php
$sql="SELECT * FROM meciuri WHERE data='2015-01-10'";
$resursa=mysql_query($sql);
if(!$resursa)
{
exit(mysql_error());
}
if(mysql_num_rows($resursa)==0)
{
print 'Nu s-a gasit niciun rezultat!<br>';
}
echo "<div class='ziua1image'>";
echo "<img src='./images/fotbal2.jpg' style='width:600px;height:300px'>";
echo "</div>";
echo "<div class='div'>";
echo "<table id='tabelMeciuri' class='display' cellspacing='0'>";
echo "<thead>";
echo "<tr class='data_cota'>";
echo "<td>Uefa Champions League</td>";
echo "<td>1</td>";
echo "<td>X</td>";
echo "<td>2</td>";
echo "<td>1x</td>";
echo "<td>x2</td>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
$resursa=mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
$idConta1=$row['id_meci']."_1";
$idConta2=$row['id_meci']."_2";
$idConta3=$row['id_meci']."_3";
$idConta4=$row['id_meci']."_4";
$idConta5=$row['id_meci']."_5";
$meci1=$row['nume_meci'];
print' <tr class="ooddd">
<td>' .$row['nume_meci'] . '</td>
<td><label id="'.$idConta1.'" onclick="getCota('.$row['id_meci'].','.$meci1.',1)" >' .$row['victorie_1'] . '</label></td>
<td><label id="'.$idConta2.'" onclick="getCota('.$row['id_meci'].',2)" >' .$row['egal_x'] . '</td>
<td><label id="'.$idConta3.'" onclick="getCota('.$row['id_meci'].',3)" >' .$row['victorie_2'] .'</td>
<td><label id="'.$idConta4.'" onclick="getCota('.$row['id_meci'].',4)" >' .$row['victorie_egal_1x'] .'</td>
<td><label id="'.$idConta5.'" onclick="getCota('.$row['id_meci'].',5)" >' .$row['victorie_egal_x2'] .'</td>
</tr>';
}
echo "</tbody>";
echo "</table>";
echo "</div>";
?>
<script>
function getCota(id,numeMeci,index){
debugger;
var idCota="#"+id+"_"+index;
var idCota2=id+"_"+index;
$("#bilet").append("<div id='optiune'><label>"+$(numeMeci).text()+"</label> <label>"+$(idCota).text()+"</label> </div>");
}
$(document).ready(function() {
$('#tabelMeciuri').DataTable();
} );
</script>
<style>
.BiletCSS{
width: 350pxpx;
height: 400px;
background-color:#989898;
float: right;
margin-right: 30px;
}
</style>
I want to select one name and one number from database and put them in a separate div, next to the table. 我想从数据库中选择一个名称和一个数字,然后将它们放在表格旁边的单独的div中。 When i try to select only the number (' .$row['egal_x'] . ') it works but if i want to add the name (' .$row['victorie_1'] . ') i don't get anything in that div and it shows me that error... Can someone tell me how i can can fix that?
当我尝试仅选择数字('。$ row ['egal_x']。')时,它可以工作,但是如果我想添加名称('。$ row ['victorie_1']。'),我什么也没得到在那个div中,它向我显示该错误...有人可以告诉我如何解决该问题吗?
As you want to insert PHP
results in to a JavaScript
String, you must build a string. 当你要插入
PHP
导致的JavaScript
字符串,你必须建立一个字符串。
Change 更改
<td><label id="'.$idConta1.'" onclick="getCota('.$row['id_meci'].','.$meci1.',1)" >' .$row['victorie_1'] . '</label></td>
to 至
<td><label id="'.$idConta1.'" onclick="getCota(\''.$row['id_meci'].'\',\''.$meci1.'\',1)" >' .$row['victorie_1'] . '</label></td>
otherwise the result of it is passed as name: 否则,其结果将作为名称传递:
// your code:
onclick="getCota(Shakhtar ,meci,1)"
// after change
onclick="getCota('Shakhtar' ,'meci',1)"
I'm not sure if this is exactly your issue, but you aren't specifying the numeMeci
parameter in the last four columns. 我不确定这是否正是您的问题,但是您没有在最后四列中指定
numeMeci
参数。 For example: 例如:
onclick="getCota('.$row['id_meci'].',2)" > // no second parameter
With it missing, your getCota(id,numeMeci,index)
is receiving the index values in numeMeci
instead of the index
parameter. 缺少它,您的
getCota(id,numeMeci,index)
在numeMeci
接收索引值而不是index
参数。 Effectively that function would be attempting something like: 实际上,该功能将尝试执行以下操作:
$(2).text()
jQuery probably doesn't like that. jQuery可能不喜欢这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.