我想在脚本中引用按钮状态

时间:2016-08-10 20:14:33

标签: javascript html css

如何从脚本中引用菜单按钮?当我在实施后单击按钮时,它似乎不正确...谢谢你的帮助!这里的问题特别针对底部脚本中的if语句,它声明if(data_type == 1){做某事}。

var data_type = 0;

function data() {

        data_type = 1;
    }

///menu-button///
<li id="menu" onclick="data()" style="max-width:82px">
            <a href="#" id="m7"> DATA </a>
</li>
<script>
document.write('<div id="div2" class="wrapper">');
document.write('<ul id="Grid">');

for (var i = 0; i < 33; i++) {
    var ch = "";
    if (i%3==0) { ch="E"; } else if (i%3==1) { ch="C"; } else { ch="W"; }
    document.write('<li id="mE'+ i + '" class="mix ' + sortSettings[i][0] + ' ' + i
                        + '" onclick="imgClicked(' + i + ')" > <div class="content"> <div><img class="bImg" id="imgI' + i
                        + '" src="ico1.jpg" width="145" height="213"></div> <div id="menu"> <img id="gI' + i + '" src="ico1.jpg" width="35" height="35" style="float:left"></div>'
                        + '<div id="descNum">' + (Math.floor(i/3)+1) + ch + '</div>'
                        + '<div id="desc">' + allSettings[i][1] + '</div>'
                        + '<div id="desc">' + allSettings[i][2] + '</div>'
                        + '<div id="desc">' + allSettings[i][0] +' '+ allSettings[i][3] + '</div></div></li>');
}

for (var i = 0; i < 11; i++) {
    for (var j = 0; j < 3; j++) {
        var add = "";
        if(data_type == 1){
            if (j==0) {
                add="E";
                $("#imgI" + ((i*3)+j)).attr("src", "Beds/20160530/" + (i+1) + add + "(1).JPG");
            } else if (j==1) {
                add="C";
                $("#imgI" + ((i*3)+j)).attr("src", "Beds/20160530/" + (i+1) + add + "(1).JPG");
            } else if (j==2) {
                add="W";
                $("#imgI" + ((i*3)+j)).attr("src", "Beds/20160530/" + (i+1) + add + "(1).JPG");
            }
        }


        else{
            if (j==0) {
                add="E";
                $("#imgI" + ((i*3)+j)).attr("src", "Beds/20160530/" + (i+1) + add + ".JPG");
            } else if (j==1) {
                add="C";
                $("#imgI" + ((i*3)+j)).attr("src", "Beds/20160530/" + (i+1) + add + ".JPG");
            } else if (j==2) {
                add="W";
                $("#imgI" + ((i*3)+j)).attr("src", "Beds/20160530/" + (i+1) + add + ".JPG");
            }
        }

    }
}

document.write('<li class="gap"></li>');
document.write('</ul>');
document.write('</div>');
</script>

0 个答案:

没有答案