我对colorbox插件有疑问,它可以工作,但问题是,当我显示一个由PHP循环生成的具有唯一id的HTML表单时,colorbox不会给你点击元素的正确id,而是,如果你点击一个随机元素来提醒它的 ID 当它在 colorbox 中时,它会按升序提醒 id .. 例如,如果我点击分配有数字 id 的第一个随机元素,它会说 1 ,然后第二个随机元素会说 2 ,而不是识别使用颜色框显示表单时单击的随机元素的 id ...没有颜色框它可以正常工作..我怎样才能将参数传递给颜色框以便可以传输 id以及将它们分配给循环的元素匹配?下面是我的代码.. 谢谢,Jquery 和 PHP
jQuery(document).ready(function() {
$("a.madscore").colorbox({inline:true, width:"350px", href: "#madcomment_menu"});
$("div#scoring_scale a").click(function(e) {
e.preventDefault();
ID = $(this).attr('id');
alert(ID);
point = $(this).text();
username = $('#username'+ID).val(); alert(username);
name = $('#name'+ID).val();
image = $('#image'+ID).val();
//var message = $('textarea#text'+ID).val(); alert(message);
var result ='Just gave @'+username+' a score of'+point+'via MadFlock';
$('textarea#text'+ID).attr("value", result);
tweet = $('textarea#text'+ID).val();
});
});
<?php
$select = "SELECT * FROM COMMENTS INNER JOIN Twitter_Data ON Twitter_Data.screen_name=Comments.Twitter WHERE Category ='Comments'";
$result = mysql_query($select);
$result_count = mysql_num_rows($result);
echo " <table border =\"0\">";
echo "<tr>";
$user_array = array();
$counter = 0;
if($result_count > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<div id ='scoring_scale' class='madscore".$row['ID']."' style='display:none;'>";
echo "<div id='madcomment_menu' style='padding:10px; background:#fff;'>";
echo "<a id='".$row['ID']."' class='green_circle' href='#'> +3 </a>";
echo "<a id='".$row['ID']."' class='orange_circle' href='#'> +1 </a>";
echo "<a id='".$row['ID']."' class='red_circle' href='#'> -1 </a>";
echo "<a id='".$row['ID']."' class='brown_circle' href='#'> -3 </a><br />";
echo"<form>";
echo "<textarea id='text".$row['ID']."'rows='5' cols='33'>";
echo "-";
echo "</textarea>";
echo"<button id='button".$row['ID']."'class='button_madscore'> MadScore </button>";
echo "</form>";
echo "</div>";
echo "</div>";
}
}
// Here is the link that will generate the COLORBOX pop-up
echo "<a id='".$row['ID']."'class=' madcomment' href='#madcomment_menu'><img src='images/madcomment.png' /> </a>";
?>