javascript:togglecomments需要添加图像+-

javascript:togglecomments需要添加图像+-,javascript,Javascript,我目前正在使用以下命令展开折叠div <style type="text/css"> .commenthidden {display:none} .commentshown {display:inline} table.gridtable td { padding:15px;} .dropdowntitle a {color:#333; fontsize:13px; text-decoration: none;} </style> HTML

我目前正在使用以下命令展开折叠div

<style type="text/css"> 
   .commenthidden {display:none}
   .commentshown {display:inline}
    table.gridtable td { padding:15px;}
   .dropdowntitle a {color:#333; fontsize:13px; text-decoration: none;}
</style>
HTML


文本在这里拉拉

但是我需要在使用这个图像显示div时将图像改为负数http://i.microsoft.com/global/ImageStore/PublishingImages/icons/icon_plus_hover.png

我想添加
+
-
符号,这样当用户单击标题时,图像会变为负号图像,等等,在这里做了一些调整


非常感谢您的帮助。

如果您不更改HTML结构,这是一个解决方案

HTML

<h4 class="dropdowntitle">
   <a href="#" onclick="togglecomments(this,'Accelerators')" aiotitle=""><img width="20" height="20" style="FLOAT: left; MARGIN: 0px 5px 0px 0px" alt="" src="http://i.microsoft.com/global/ImageStore/PublishingImages/icons/icon_plus.png" /> Read more details</a>
</h4>

删除
href=“javascript://”
到内联函数调用
onclick
。其实这也不是最好的做法。当您对此感到满意时,请尽量避免内联调用,并使用Javascript进行触发:
document.getElementById('Example').onclick=function(){…

非常感谢您的回答这正是我想要的needed@user3086580由于您是新来的,请在选择答案时阅读以下内容:
<div class="commenthidden" id="Accelerators">
    <p>text here lalala</p>
    <p>but I need the image to change to the minus when the div is shown using this image http://i.microsoft.com/global/ImageStore/PublishingImages/icons/icon_plus_hover.png</p>
</div>
<h4 class="dropdowntitle">
   <a href="#" onclick="togglecomments(this,'Accelerators')" aiotitle=""><img width="20" height="20" style="FLOAT: left; MARGIN: 0px 5px 0px 0px" alt="" src="http://i.microsoft.com/global/ImageStore/PublishingImages/icons/icon_plus.png" /> Read more details</a>
</h4>
function togglecomments (that,postid) {
    var img =that.firstElementChild;
    var whichpost = document.getElementById(postid);

   if (whichpost.className=="commentshown") {
      whichpost.className="commenthidden";
      img.src='http://i.microsoft.com/global/ImageStore/PublishingImages/icons/icon_plus.png'; 
   } else { 
      whichpost.className="commentshown";
      img.src='http://i.microsoft.com/global/ImageStore/PublishingImages/icons/icon_plus_hover.png';
   }
}