我有以下 jquery 代码将#content
div 从另一个页面加载到当前#result
页面的div 中:
$('a').click(function(event){
$('#result').load('abother_page.html #content');
});
如您所见,我将请求文件的名称以及我要显示的特定 div 硬编码到使用 load 方法发送的字符串中。
我试图使这个动态,但我的代码缺少一些东西:
// get the href of the link that was clicked
var href=$(this).attr('href');
// pass the href with the load method
$('#result').load('href #content');
显然这不起作用,因为我创建的 href 变量没有插入到字符串中。我怎样才能做到这一点?
我尝试了以下方法,但均未成功:
// Ruby-style:
$('#result').load('#{href} #content');
// Concatenating-style
$('#result').load(href + '#content');