如何为列表中的php生成的jquery对话框创建唯一的id:s?

时间:2022-08-24 15:49:09

I have a problem with jquery dialogs. When using them just hardcoded on to a button they work just fine. But when I run through a vector in php to generate some search results, my more info button stops working. The first option will generate a dialog when pressed, the content in it however is wrong. List items after this one will not show a dialog popup and if I press on a button when scrolled down it jumps up to the first item.

我有一个jquery对话框的问题。使用它们只需硬编码到一个按钮,他们工作得很好。但是当我在php中运行一个向量来生成一些搜索结果时,我的更多信息按钮停止工作。第一个选项会在按下时生成一个对话框,但其中的内容却是错误的。在此之后列出项目不会显示对话框弹出窗口,如果我向下滚动按钮时它会跳转到第一个项目。

My guess is that this behavior is generated due to multiple buttons with the same id. This is the first homepage I've made and I do not really know how to tackle this problem.

我的猜测是由于具有相同id的多个按钮而产生此行为。这是我制作的第一个主页,我真的不知道如何解决这个问题。

Some code:

一些代码:

PHP part:

$outputList = '';
while($row = mysql_fetch_array($sql2)){

  ...yadayada...
  <a style="position:relative;left:600px;top:-40px;" href="#" id="dialog_link" onmouseover="document.rollover.src=button2.src" onmouseout="document.rollover.src=button1.src" >
    <img src="images/search/info_btn_unsel.png" border="0" name="rollover" />
  </a>
</div>
</div>
}

JavaScript part:

<script type="text/javascript">
  $(document).ready(function(){
    // Dialog           
    $('#dialog').dialog({
      autoOpen: false,
      width: 600,
      buttons: {
        "Ok": function() { 
          $(this).dialog("close"); 
        }, 
      }
    });

    // Dialog Link
    $('#dialog_link').click(function(){
      $('#dialog').dialog('open');
      return false;
    });
  });
</script>

complete file can be found here: http://dl.dropbox.com/u/10627595/timeseek_result.php

完整的文件可以在这里找到:http://dl.dropbox.com/u/10627595/timeseek_result.php

Thanks

谢谢

4 个解决方案

#1


0  

If each dialog box has information in it unique to each row of search results, then each dialog needs its own unique id. Also, each dialog box content needs php variables that are unique for each row.

如果每个对话框中包含对每行搜索结果唯一的信息,则每个对话框都需要其自己的唯一ID。此外,每个对话框内容都需要每行唯一的php变量。

After reading your question and looking at your code, this appears to be the case. If I am correct, then solving your problem will be a little more involved than changing the id's to classes.

在阅读了您的问题并查看您的代码后,情况似乎就是如此。如果我是正确的,那么解决问题将比将id更改为类更复杂。

#2


0  

You must never have repeated ids, this was causing the problem. Use a class instead

你必须永远不会有重复的id,这导致了问题。请改用一个班级

So you'd have:

所以你有:

<a class="dialog_link" ... >

And your jquery code would be:

你的jquery代码将是:

$('.dialog_link').click(function(){ //Note the . instead of #
   $('#dialog').dialog('open'); //The same code
   return false; //The same code
});

Hope this helps. Cheers

希望这可以帮助。干杯

#3


0  

You can't have more than one item with the same id, an ID has to be unique.

您不能拥有多个具有相同ID的项目,ID必须是唯一的。

Add some unique ID from your database results to the ID of your html link.

将数据库结果中的一些唯一ID添加到html链接的ID中。

Then add a class "js_show_info" or the like to your link and attach your jQuery handler to this class.

然后在链接中添加一个类“js_show_info”等,并将jQuery处理程序附加到此类。

$('.js_show_info').click()...

#4


0  

As everyone else already mentioned, you need to have unique IDs. Make a class dialog_link and assign IDs inside the while loop equal to a unique value, such as the SQL table row number of a given record.

正如其他人已经提到的那样,您需要拥有唯一的ID。创建一个类dialog_link并在while循环内分配ID等于唯一值,例如给定记录的SQL表行号。

#1


0  

If each dialog box has information in it unique to each row of search results, then each dialog needs its own unique id. Also, each dialog box content needs php variables that are unique for each row.

如果每个对话框中包含对每行搜索结果唯一的信息,则每个对话框都需要其自己的唯一ID。此外,每个对话框内容都需要每行唯一的php变量。

After reading your question and looking at your code, this appears to be the case. If I am correct, then solving your problem will be a little more involved than changing the id's to classes.

在阅读了您的问题并查看您的代码后,情况似乎就是如此。如果我是正确的,那么解决问题将比将id更改为类更复杂。

#2


0  

You must never have repeated ids, this was causing the problem. Use a class instead

你必须永远不会有重复的id,这导致了问题。请改用一个班级

So you'd have:

所以你有:

<a class="dialog_link" ... >

And your jquery code would be:

你的jquery代码将是:

$('.dialog_link').click(function(){ //Note the . instead of #
   $('#dialog').dialog('open'); //The same code
   return false; //The same code
});

Hope this helps. Cheers

希望这可以帮助。干杯

#3


0  

You can't have more than one item with the same id, an ID has to be unique.

您不能拥有多个具有相同ID的项目,ID必须是唯一的。

Add some unique ID from your database results to the ID of your html link.

将数据库结果中的一些唯一ID添加到html链接的ID中。

Then add a class "js_show_info" or the like to your link and attach your jQuery handler to this class.

然后在链接中添加一个类“js_show_info”等,并将jQuery处理程序附加到此类。

$('.js_show_info').click()...

#4


0  

As everyone else already mentioned, you need to have unique IDs. Make a class dialog_link and assign IDs inside the while loop equal to a unique value, such as the SQL table row number of a given record.

正如其他人已经提到的那样,您需要拥有唯一的ID。创建一个类dialog_link并在while循环内分配ID等于唯一值,例如给定记录的SQL表行号。