[英]Which event i must use?
我有这个代码:
htmlDiv+="<DIV class='addon-checkbox'
onclick='event.stopPropagation();__toogleEnabled(\""+__addons[i]+"\", this);'
if (localStorage[\"__Enable__\"+__addons[i]]==\"yes\")
this.style.backgroundPosition= \"0 -50px\"; >";
当单击此div function __toogleEnabled
正确更改图像的背景位置,但其余代码则function __toogleEnabled
。 我想this
(接收当前元素)或整个指令
if(localStorage[\"__Enable__\"+__addons[i]]==\"yes\")
this.style.backgroundPosition= \"0 -50px\"; >";
不要工作,因为没有事件。 但是我不知道发生什么事。
可能是可以用其他解决方案解决的。 我只希望background-position
值为“ 0 -50px”, if localStorage[\\"__Enable__\\"+__addons[i]]
"yes" when page loaded
if localStorage[\\"__Enable__\\"+__addons[i]]
值为"yes" when page loaded
,但必须仅对当前div进行,因为有许多其他具有相同类且没有ID的div。
我认为您的报价含糊不清。 您的代码需要更改为:
htmlDiv+='<div class="addon-checkbox" '+
'onclick="event.stopPropagation();__toogleEnabled(\''+__addons[i]+'\', this);'+
'if(localStorage[\'__Enable__\'+__addons[i]]==\'yes\')'+
'this.style.backgroundPosition=\'0 -50px\';" >';
但是,执行所有这些操作的更好方法是使用DOM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.