【发布时间】:2013-07-03 09:15:20
【问题描述】:
我有一个包含多个具有相同类的 div 的页面。我想打开一个模态窗口,然后用 JSON/动态内容填充模态。为此,我需要获取正确的 url 以在 getJson 语句中使用。所以我有一个包含多个产品的页面,如下所示:
HTML
<div class="product" style="opacity: 1;">
<a title="product" **href="url-to-product.com"**>..................</a>
<h3><a href="url-to-product.com">Blabla</a></h3>
<div class="button opener">...</div>
</div>
<div class="product" style="opacity: 1;">
<a title="product" **href="other-url-to-product.com"**>..................</a>
<h3><a href="other-url-to-product.com">Blabla</a></h3>
<div class="button opener">...</div>
</div>
当我单击按钮时,会弹出一个模式。现在我想用内容填充那个模式。因此我需要 ** ** 之间的 href 值。只有一个来自当前点击的产品offcourse。所以我有的是这样的:
JQUERY
$(".opener").live("click", function(event) {
event.preventDefault();
$.get($(this).attr('href'), function(data, status) {
$("#dialog").dialog("open");
var url = $(this).find('h3 > a').attr('href');
//这不起作用,需要像上面提到的那样来自href的值
$.getJSON(url, function(data) {
$.each(data.product, function(index, product){
......... etc .......
【问题讨论】:
标签: jquery json modal-dialog