单击时,Colorbox无法识别随机元素的ID,当您随机点击元素时,它会按升序警告ID。如何在点击任何元素时显示正确的ID?
JavaScript代码
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代码
<?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=' madscore' href='#madcomment_menu'><img src='images/madcomment.png' /> </a>";
?>