我使用jQUery UI Position插件:
http://jqueryui.com/position/将我的图标放在网页上.选择器从数据库中获取并使用PHP在$myselector变量中输出到JS.这是我目前的代码:
var element_selector='<?PHP echo $myselector;?>';
$('#inline_docxdiv .Featured.Slider').position({
my: "center",at: "right top",of: $(element_selector)
});
//append icons,applicable to all
$(divname<?PHP echo $uniqueid;?>).append('
');但是,图标未正确附加,并在控制台中返回错误:
Uncaught TypeError: Cannot read property ‘nodeType’ of undefined
奇怪的是,如果我在JS代码中硬编码选择器(不是由PHP输出),一切正常,控制台中没有返回错误.这是我对元素选择器进行硬编码的代码:
var element_selector='.idoc-featured-slider';
有没有办法使用PHP输出选择器而不会遇到错误?谢谢你的帮助.