我試圖在點擊一個查看按鈕時顯示div詳細信息,這些按鈕在使用jquery的while循環中顯示,但它只顯示第一條記錄,不顯示其餘記錄,任何人都可以告訴我解決這個問題..Jquery腳本沒有在while循環中運行
下面是示例代碼:
<html>
<head>
<script src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
$('#view').click(function() {
var user=$('#user').text();
alert(user);
});
});
</script>
<style type="text/css">
#content div{display:inline-block;}
</style>
</head>
<body>
<?php
$i=0;
while($i<5)
{
?>
<div id="content">
<div id="user">Street(<?=$i+1?>)</div>
<div id="view" style="color:green;cursor:pointer;">View</div>
</div>
<?php
$i++;
}
?>
</body>
</html>
多個唯一的ID是不允許的。切換到課程。 – ahren 2013-04-04 06:05:44
ID必須是唯一的。改爲使用班級。 – Barmar 2013-04-04 06:05:46