在用户图像选择时更改div背景

时间:2013-10-09 03:45:56

标签: javascript

我有div,thumbwrap1,它会在选择图像时改变颜色,但我感到困惑的是当用户选择另一张图像时如何删除当前所选div的背景?

       <script type="text/javascript"> 

        function doOnChannelLoad(e) {   

    if (e.mediaList && e.mediaList.length > 0) {

      var playlistHTML = "";

      for (var i = 0; i < e.mediaList.length; i++) {
        var media = e.mediaList[i];
        if (media) {
          playlistHTML += '<div id="thumbwrap">';
          playlistHTML += '<div id="thumbwrap1"  onClick="javascript:myFunction(this);">';
          playlistHTML += '<a href="javascript:onPlaylistItemClick(\'' + media.id + '\');">';
          playlistHTML += '<img width="105"  border "1" src="' + media.thumbnailUrl + '"/ >';
           playlistHTML += '</div>';
          playlistHTML += '<div id="thumbwrap-title">' + media.title + '</div>';
          playlistHTML += '</a>';
          playlistHTML += '</div>';
        }
      }

      playlistHTML += '<br style="clear:both;" />';

      var playlistBox = document.getElementById('playlist-box').innerHTML = playlistHTML;
      drawBorder(e.id);

    }

  }

  function onPlaylistItemClick(mediaId) {

    DelvePlayer.doSetMedia(mediaId, false);

  }

  function onChannelListClick(channelId) {

    DelvePlayer.doLoadChannel(channelId);

  }  

  function drawBorder(elementId) {

    $('li').removeClass('channelSelected');
    document.getElementById(elementId).setAttribute("class", "channelSelected");

  }  

function myFunction(divObj){

divObj.style.background="#E79F2C";
 $(this).remove(divObj);

}

感谢。

0 个答案:

没有答案