有人可以向我解释为什么不能将包含空格的字符串作为参数传递给 javascript 函数吗?
这是我的代码,它显示了这个问题,只需将鼠标悬停在链接上,你就会看到只有“mario”显示为标题,而不是“mario and luigi”
var href='mario and luigi', subject=$('div').data('subject'),
size=$('div').data('reviewid'),
src=$('div').data('itemid'), className='mini';
function formatLink(href, subject, src, size, className){
if(size=='mini')
size='height:25px; width:25px;';
else if(size=='medium')
size='height:40px; width:40px;';
else if(size=='large')
size='height:125px; width:125px;';
else if(size=='xlarge')
size='height:180px; width:260px;';
return '<a class="pjax" href='+href+' title='+subject+'><span class='+className+'><span class="image-wrap" style="position:relative; display:inline-block; background:url('+src+') no-repeat center center;'+size+'" ><img style="opacity:0;"></span></span><span title='+subject+'>'+subject+'</span></a>';
}
var link=formatLink(href, subject, src, size, className);
$('div').html(link);