开发者

How to send attributes via onmouseup?

开发者 https://www.devze.com 2023-01-01 17:42 出处:网络
I开发者_开发知识库\'m ajaxing my content and can\'t figure out why i can\'t pass a variable to my function event:

I开发者_开发知识库'm ajaxing my content and can't figure out why i can't pass a variable to my function event:

..somewhere inside the each loop

var file = 'something';

html+='<li><a href="" onclick="return false;" onmouseup="preview('+file+');" style="background: url('link') no-repeat;"></a></li>';

}

function preview(file)
...
  alert(file);


What the quoted text looks like with your variable added:

'<li><a href="" onclick="return false;" onmouseup="preview(something);" style="background: url('link') no-repeat;"></a></li>'

Something isn't enclosed in quotes in the concenated string.


If your problem is loop you have to add your variable into a closure

--- loop ---
// file is updated into teh loop
html+=(function(loopedVar){
    return '<li><a href="" onclick="return false;" onmouseup="preview('+loopedVar+');" style="background: url('link') no-repeat;"></a></li>';
})(file);

--- end loop ---
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号