Colorbox无法识别分配给元素的ID,如何通过colorbox传递唯一ID?

时间:2013-08-03 23:20:39

标签: php javascript jquery colorbox

我有一个colorbox插件的问题,它可以工作,但问题是,当我显示一个HTML表单,其中包含由PHP循环生成的唯一ID时,colorbox不会为您提供所单击元素的正确ID,相反,如果你点击一个随机元素来提醒它在彩盒中的ID,它会按升序警告id。所以例如,如果我点击分配了数字id的第一个随机元素,它会说1 ,然后第二个随机元素将说2,而不是识别随着彩色框显示表单时点击的随机元素的ID ...没有颜色框它工作正常..我怎么可能将参数传递到彩盒,以便ids的也可以转移并匹配它们分配给循环的元素?下面是我的代码..谢谢,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>";
    ?>

0 个答案:

没有答案