我有这样的代码,我需要设置一个唯一的title
:如何将变量插入到变量字符串中?
var tmpImg = '<img src="/admin/icons/cross.png" title="' + title + '" />';
$(this).find("tr td input").each(function(){
title = $(this).attr("value");
$(this).hide().before(tmpImg);
});
我希望发生的,就是每一次迭代each
在<input>
,它将更新tmpImg
字符串title
值。我知道我可以像下面那样分开img HTML,但我认为当我需要在后面的脚本中重新使用图像时,这会变得混乱。
var tmpImg = '<img src="/admin/icons/cross.png" title="';
$(this).find("tr td input").each(function(){
title = $(this).attr("value");
$(this).hide().before(tmpImg + title + '" />');
});
我觉得轻度有趣,你拼写单词“变量”两种不同的方式 - 无论是不正确 - [在问题标题](http://stackoverflow.com/posts/8969771/revisions#revbac494ba-2a4a-4d42-987e-d10db9de3e62):-) –