2013-02-18 82 views
1

我的目标是让用户点击一个标记链接并弹出一个对话框,让用户输入一些文字来解释情况。我不确定我应该如何设置它,以便标记链接只会拉出连接到被标记的帖子的对话框。以下是我迄今为止:如何使用jQuery对话框小部件标记帖子?

的jQuery:

$(document).ready(function() { 

    $(".flagDialog").dialog({ 
     autoOpen: false, 
     resizable: false, 
     width: 550  
      }); 

    $(".flag").click(function() { 
     var target = $(this); 
     $(".flagDialog").dialog("open"); 
     $(".flagDialog").dialog("widget").position({ 
      my: 'left top', 
      at: 'left bottom', 
      of: target 
     }); 
    }); 
}); 

HTML:

while($row = mysql_fetch_assoc($result)) { 
    extract($row); 

    <div class='flag'>Flag</div> 
    <div class="flagDialog" title="Flag"> 
     <form action="flag.php" class="flagForm" method="post"> 
      <textarea name="flag_input" class="flagInput" rows="6" cols="55"><?php echo $username; ?></textarea> 
     </form> 
    </div> 
    } 

目前,当我点击任何一个已经消失了扔对话框的标志链接的所有而循环弹出,这是有道理的,我只是不知道我应该如何去区分它们,并在jQuery端处理它。

回答

0

你无论如何都必须给标志有关自身somemore信息,其中产生旗格会比看起来像这样的行:

<div class="flag" alt="<?php echo $row->ID; ?>">Flag</div> 

你只存储有关标志的信息在alt -Attribute的div

在jQuery的你比指的是ALT属性这样的:

$(".flag").click(function() { 
    var alt = $(this).attr("alt"); //Do something with it. 
0

您需要确定每一个“标志”,并分别对话框(通过ID,类或其他属性)

OR

如果你的代码的HTML看起来像你的榜样,您可以使用next() selector

$(".flag").click(function() { 
    $(this).next('div.flagDialog').dialog("open"); 
    $(this).next('div.flagDialog').dialog("widget").position({ 
     my: 'left top', 
     at: 'left bottom', 
     of: $(this) 
    }); 
}); 
相关问题