日期:2014-05-16  浏览次数:20402 次

js 控制显示加减号

方法1:

<td id="imgmenu1" height="28" class="menu_title" style="cursor:hand"><img id="i1" src="images/NodeClose.jpg" onclick="chkClick(this);" /><span>社会科</span></td>


<script type="text/javascript">
<!--
function chkClick(img)
{
img.src = img.src.toLowerCase().indexOf("NodeClose.jpg")!=-1?"images/NodeOpen.jpg":"images/NodeClose.jpg";
-->
</script>

方法2:
<script type="text/javascript">
var SwitchPicArr = new Array("../Images/black_minus.jpg","../Images/black_plus.jpg")
   
function setDetailMsgRow(rowID, btn) {
        var row = document.getElementById(rowID);
        if (row != null) {
            if (row.style.display == (document.all ? "block" : "table-row")) {
                row.style.display = "none";

                 if (btn != null) {
                     btn.style.backgroundImage = "url(" + SwitchPicArr[1] + ")";
                }
            }
            else {
                row.style.display = (document.all ? "block" : "table-row");
                if (btn != null) {
                    btn.style.backgroundImage = "url(" + SwitchPicArr[0] + ")";
                }
            }
        }

//        if (btn != null) {
////            if (btn.value != "Hide Detail") {
////                btn.value = "Hide Detail";
////            }
////            else {
////                btn.value = "Display Detail";
////            }

//        }

    }

</script> 


.cshtml 部分:
  @if (item.MessageDetail == "")
                                { @Html.Raw(" ")}
                                else { 
                                     <input type=button value="" onclick="setDetailMsgRow('@sTmpRowID',this)" style="background:url(../Images/black_plus.jpg);width:40px;height:40px