我为我缺乏jquery知识而道歉。在我正在构建的这个网站中,用户可以看到一些代表植物的缩略图。单击缩略图时,将启动jquery弹出窗口。我希望能够做的是将一个具有植物ID的php变量传递给jquery弹出窗口,以显示打印机信息。任何帮助都将不胜感激。谢谢。
编辑:http://www.plantcombos.com/header/main_index.php?display=random_mix
发布于 2012-03-30 22:39:58
使用PHP方法从jQuery文件收集数据并将其显示在页面上。它非常简单,您可以将任何您喜欢的变量(参数)传递到页面。
http://api.jquery.com/jQuery.ajax/
例如:
// This will send a request to a PHP page
$.ajax({
url: "http://example.com/test.php",
dataType: "html",
success: function(data){
// Place the returned data into your content
$('#image').html(data);
}
});发布于 2012-03-30 22:39:35
我非常确定你不需要每次都查询PHP……像这样的东西会起作用的:
<img class-"imgclick" src="/small-plant.jpg" data-id="123" />这将是您的服务器端的输出(如果您使用的是php)-它将图像的ID存储在data属性中
JavaScript:
$(document).ready(function() {
$('.imglink').click(function(event) {
event.preventDefault();
$('dialogid')
.data('image_id', $(this).data('id'))
.dialog('open');
})
})然后,将来自data属性的图像id传递给对话框的data属性。可以使用对话框中的$(this).data('image_id')表单访问此属性,然后
https://stackoverflow.com/questions/9945027
复制相似问题