【发布时间】:2016-05-26 01:46:35
【问题描述】:
我正在尝试将变量用作 jQuery 选择器,但它在控制台中输出错误:
错误:语法错误,无法识别的表达式:# in jquery.2.1.4.min.js
有人解释为什么会发生这种情况吗?
function FileSelected(file) {
var imgId = RoxyUtils.GetUrlParam('img');
$(window.parent.document).find("#" + imgId).attr('src', file.fullPath);
$(window.parent.document).find("#" + imgId).next().val(file.fullPath);
window.parent.closeCustomRoxy();
}
【问题讨论】:
-
imgId的值是多少 -
尝试在定义变量
var imgId= "#"+RoxyUtils.GetUrlParam('img');时添加主题标签。另外,请在定义后立即console.log(imgId);,让我们知道你看到了什么。 -
img的id attr。例如:“img1”。
-
只有
.find('#')在我的控制台中给出了这个错误,所以我假设imgId是空白、空等。 -
抱歉,我没有看到 BenG 的评论。我发布了类似的答案
标签: javascript jquery html jquery-selectors