我很难告诉我的jQuery函数(它位于一个php程序中)来识别动态生成的表中的正确行,该表在表的每一行中都显示了一张照片。我希望使用Ajax " load“方法将属于照片的标记加载到单元格中的div中--仅--用户单击的照片表中的特定行。此表中的行数由一个变量定义,而我事先不知道该变量的值。表中的每一行都有以下div:
echo "
$Photo_Counter = 0; // set $Photo_Counter to zero before
searching through photos in a database
<table>
...foreach loop // this loop brings up all the photos found
in a search through a database
$Photo_Counter = $Photo_Counter + 1;
...
<tr>
<td>$Photo_Counter</td> // this shows the number of the row
<td>
<div class='see_raw_tags'>
<a href='flickr_photos_getInfo.php?Photo_ID=$photo_id'>see the tags</a>
</div>
<div class='raw_tags'> //this is the place that should receive the photo's tags
</div>";
</td>
<td>$Photo</td> //this shows a photo
</tr>
</table>每个表行中的div class='see_raw_tags'包含一个唯一的超链接,用户可以在该链接上单击以查看该行中照片的标记。这将触发jQuery函数,使用Ajax方法将标记加载到空的"raw_tags“div区域。
这是jQuery/Ajax编码:
<script>
$(document).ready(function()
{
$('.see_raw_tags a').click(function(e)
{
var url = $(this).attr('href');
$('.raw_tags:nth_child('+photo_counter')').
html('loading...').load(url);
var photo_counter = <?php echo $Photo_Counter; ?>;
e.preventDefault();
});
});
</script>在生成表期间,我在php (名为:$Photo_Counter)中运行了一个行计数器。现在,我希望只在用户使用php变量$Photo_Counter单击的行中插入照片的标记,首先将其转换为名为photo_counter的JavaScript变量。但这是行不通的。我只看到正确的标签出现在一个新的浏览器屏幕,而不是在适当的单元格和表格中的照片行。
问题:我相信问题就在jQuery编码中。但我在这里错过了什么?我做错什么了?
发布于 2015-12-17 17:26:37
它是一个新窗口,还是由于html函数而将当前窗口的html替换为标记?
试试看。(这个).htm..。ans从那里开始,而不是html()。
如果我是您,我会将行的id添加到包含url的对象中,所以在呈现表时添加一个href.data-rownum=“$photocounter”,在js中您可以执行$(This).parent().load(.)
https://stackoverflow.com/questions/34340299
复制相似问题