将变量传递到jquery load()函数语法中 [英] Passing a variable into a jquery load() function syntax
问题描述
我试图找出如何将变量字符串staffID传递给load()函数中的id选择器.这是一段代码:
I am trying to find out how to pass that a variable string staffID into an id selector in the load() function. Here is the piece of code:
$('li.staffAsset').click(function () {
var staffID = $(this).attr("id");
openDialog('#descrDialog');
$('#staffDescr p').load('/staffDescr.html $("#" + staffID)');
});
这不起作用.基本上在staffDescr.html中有id为"staffID"的div. 我只是似乎找不到合适的语法将该变量字符串作为适当的ID传递给load()函数. 有人可以帮忙吗?
This doesn't work. Basically there are divs with id="staffID" inside the staffDescr.html. I just can't seem to find the proper syntax to pass that variable string as a proper id into the load() function. Can anyone help please?
推荐答案
您不要将dollar函数传递给字符串.只需使用此:
You don't pass the dollar function into the string. Just use this:
$('#staffDescr p').load('/staffDescr.html #' + staffID);
请参阅文档: 正在加载页面片段 .
See the documentation: Loading Page Fragments.
此外,也不需要$(this).attr("id")
.只需使用this.id
:
Also, there's no need for $(this).attr("id")
. Just use this.id
:
$('li.staffAsset').click(function () {
openDialog('#descrDialog');
$('#staffDescr p').load('/staffDescr.html #' + this.id);
});
这篇关于将变量传递到jquery load()函数语法中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!