1

我有一个 html 页面(例如 index.html),它有 10 个链接 10 个位置,每次用户单击任何链接时,不同类型的内容都必须动态加载到单个 div 中。该 div 必须放置在 jquery modal.the div 实际上仅在该 html 页面内(index.html),但 div 内容根据用户单击 URL 以模态加载。我怎样才能实现这一点?我是 jquery 和 javascript 的新手。

4

2 回答 2

0

Try something like this:

HTML

<div id="dialog-modal" title="Basic modal dialog">
  <p>Adding the modal overlay screen makes the dialog look more prominent because
  it dims out the page content.</p>
</div>

<div id="somedivwithcontent1" style="display:none">
   Text to put into the modal dialog.
</div>

JS

  var link = 1; //get from clicked link
  $( "#dialog-modal p" ).html( $('#somedivwithcontent'+link).html() );
  $( "#dialog-modal" ).dialog({
    height: 140,
    modal: true
  });

This code will get the content of the #somedivwithcontent divs and place it into the paragraph of the modal dialog. Should achieve what you wanted.

于 2013-02-13T01:57:39.827 回答
0

我能想到的最简单的方法是使用jQuery .load()函数。它使用起来非常简单,它在选择器上运行,并将使用 HTML 页面的子集加载所选元素。因此,如果您的 div 名为“fred”,并且您希望将另一个页面上名为“bob”的 div 中的文本放入名为 fred 的 div 中,则可以使用如下内容:

$('#fred').load(' http://alice.com/carol.html #bob');

它在链接页面上有很好的记录。

于 2013-02-13T01:53:45.603 回答