2013-02-13 42 views
1

我有一个html页面(对于ex index.html),它有10个链接10个位置,每次用户点击任何链接时,不同类型的内容必须加载到单个动态的div。 div必须放置在jquery modal中。div实际上只在html页面内(index.html),但div内容根据用户点击URL加载模式。我如何实现这一点?我是新来的jQuery和JavaScript。在点击或Url链接上加载不同内容到单个div上

+2

欢迎来到StackOverflow!你尝试过什么吗?请显示您的代码,以便有人能够提供帮助。查看[关于页面](http://stackoverflow.com/about)了解更多关于如何在这里提出问题的信息... – 2013-02-13 01:47:11

+0

我并不是想把它放在另一个页面上,内容已经在div中,但它必须在弹出窗口中弹出,这可以通过模态完成。但问题是模式中的内容必须基于url点击进行动态加载 – user1765427 2013-02-13 01:57:36

回答

0

我能想到的最简单的方法是使用jQuery .load()函数。使用非常简单,它在选择器上运行,并将选定元素加载到HTML页面的子集中。因此,如果你的div被称为“fred”,并且你想将另一个页面上的一个叫做“bob”的div的文本放到名为fred的div中,你可以使用类似这样的东西:

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

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

0

尝试这样:

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 
    }); 

此代码将得到#somedivwithcontent的div的内容,并将其放置到的段落模态对话框。应该达到你想要的。

相关问题