Uncaught Error: Syntax error, unrecognized expression: "#SWCX[pstid]

		var data = {"data":[{"pstid":100001,"id":"SWCX","pstx":670,"psty":109},{"pstid":100002,"id":"FWCX","pstx":830,"psty":269},{"pstid":100003,"id":"BWCX","pstx":510,"psty":189},{"pstid":100004,"id":"NBTX","pstx":192,"psty":109},{"pstid":100005,"id":"LXFS","pstx":350,"psty":269},{"pstid":1000016,"id":"CYXZ","pstx":192,"psty":29},{"pstid":100006,"id":"SWCX2","pstx":830,"psty":109},{"pstid":100007,"id":"SWCX1","pstx":510,"psty":269},{"pstid":1000015,"id":"SWCX3","pstx":350,"psty":29},{"pstid":100008,"id":"SWCX4","pstx":350,"psty":109},{"pstid":100009,"id":"LXFS2","pstx":670,"psty":189},{"pstid":100010,"id":"CYXZ2","pstx":350,"psty":189},{"pstid":100011,"id":"SWCX5","pstx":192,"psty":189},{"pstid":100012,"id":"SWCX6","pstx":510,"psty":29},{"pstid":100013,"id":"SWCX7","pstx":670,"psty":29},{"pstid":100014,"id":"SWCX8","pstx":830,"psty":29},{"pstid":100017,"id":"FWCX9","pstx":830,"psty":189},{"pstid":100018,"id":"FWCX8","pstx":510,"psty":109}]};
var obj = eval(data).data;

function init(){
console.log(obj.length);
for(var i=0;i<obj.length;i++){
//alert('"#'+ obj[i].id + '[pstid='+obj[i].pstid+']"');
//$('"#'+ obj[i].id + '[pstid='+obj[i].pstid+']"').parent().css({"position":"absolute"});
[color=red]$("#" + obj[i].id + '[pstid='+obj[i].pstid+']')[/color].css({"padding-top":"0px"});
$("#" + obj[i].id + '[pstid='+obj[i].pstid+']').parent().offset({top:(parseInt(obj[i].psty)) ,left:(parseInt(obj[i].pstx))});
}
}

以上代码报:Uncaught Error: Syntax error, unrecognized expression: "#SWCX[pstid]
解决办法:$(("#" + obj[i].id + '[pstid='+obj[i].pstid+']')),在#id外边再加一层括号即$((#id))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值