现在,当用户单击图像时,图像会突出显示。我要做的是在加载时,第一张图片将突出显示,直到用户点击另一张图片。但是,它不起作用。我这样做完全错了吗?
for (var i = 0; i < e.mediaList.length; i++) {
var media = e.mediaList[i];
if (media) {
playlistHTML += '<div id="thumbwrap" >';
if (i == 0){
playlistHTML += '<a id="thumbwrap1" href="javascript:onPlaylistItemClick(\'' + media.id + '\');" onClick="javascript:highlightLink(this);" onload ="javascript:highlightLink(document.getElementById(this));">';}
else{
playlistHTML += '<a id="thumbwrap1" href="javascript:onPlaylistItemClick(\'' + media.id + '\');" onClick="javascript:highlightLink(this);" >';} #call function here
playlistHTML += '<img width="106" height="62" style="padding:2px;" src="' + media.thumbnailUrl + '"/>';
playlistHTML += '<div id="thumbwrap-title">' + media.title + '</div>';
playlistHTML += '</a>';
playlistHTML += '</div>';
}
}
激活图像高亮功能。
var highlightLink = function () {
var active = null, colour = '#FF8C00';
if (this.attachEvent) this.attachEvent('onunload', function () {
active = null;
});
return function (element) {
if ((active != element) && element.style) {
if (active) active.style.backgroundColor = '';
element.style.backgroundColor = colour;
active = element;
}
};
}();