0
我有一個DIV #Message_PHPVARABLE應該出現在帖子的底部,當一個單選按鈕分配給這個帖子被選中。但是,發生的情況是,它對Post_1正常工作,但是當我爲Post_2選擇一個選項時,Post_1的選項會更改,並且Message_1會顯示新的選擇,而不是讓Post_2選擇顯示在Message_2中...有幫助嗎?單選按鈕的選項是「喜歡和不喜歡」。jQuery變量名爲單選按鈕不能顯示消息
$data = mysql_query("SELECT * FROM Test");
$counter = 1;
while($row = mysql_fetch_array($data)){
?>
<script type="text/javascript">
$(document).ready(function() {
$("input[name*='like_<?php $counter; ?>']").click(function() {
var defaultValue = $("label[for*='" + this.id + "']").html();
var defaultm = "You have chosen : ";
$('#Message_<?php $counter; ?>').html('').html(defaultm + defaultValue + ' | Value is : ' + $(this).val());
});
});
</script>
<div id="post_<?php $counter; ?>" class="post">
<b><?php echo $row['Title']; ?></b><br>
Expires: <?php echo $row['Exp']; ?><br>
<ul id="listM"></ul>
<div class="left"><p><input id="like_<?php $counter; ?>" type="radio" name="like_<?php $counter; ?>" value="1" />
<label for="like_<?php $counter; ?>">Like</label></p></div>
<div class="right"><p><input id="dislike_<?php $counter; ?>" type="radio" name="like_<?php $counter; ?>" value="0" />
<label for="dislike_<?php $counter; ?>">Dislike</label></p></div>
<hr />
</div>
<div id="Message_<?php $counter; ?>"></div>
<?php
$counter += 1;
}
?>
如果我硬編碼的一切(去除$櫃檯),那麼它工作正常,但顯然,要顯示在MySQL的潛在行無限多的,我必須使用變量...
WOW,這是一個業餘的錯誤! – Sweepster