猿问

小白!请问我该怎么在java中提取变量呢 ?有什么更好的颁发?

<script language="javascript">
var a,b,c,d;
a=id;
b=id;
c=id;
d=a+b+c;
</script>
<div value="7" id="key_n7" class="bd f_l" onclick="alert(this.value)" onMouseOver="this.style.backgroundColor='#D4ECEE';" onMouseOut="this.style.backgroundColor='white'" style="cursor:pointer;">7</div>
<div value="8" id="key_n8" class="bd f_l" onclick="alert(this.value)" onMouseOver="this.style.backgroundColor='#D4ECEE';" onMouseOut="this.style.backgroundColor='white'" style="cursor:pointer;">8</div>
<div value="9" id="key_n9" class="bd f_l" onclick="alert(this.value)" onMouseOver="this.style.backgroundColor='#D4ECEE';" onMouseOut="this.style.backgroundColor='white'" style="cursor:pointer;">9</div>
<div value="+" id="key_na" class=" bd f_l" onclick="alert(this.value)" onMouseOver="this.style.backgroundColor='#D4ECEE'" onMouseOut="this.style.backgroundColor='white'" style="cursor:pointer;">+</div>

在下新手刚刚接触JS,请问,上面的代码中,我怎么样才能,把7 8 9提取出来,存到变量a b c中,然后再提取'+',将7 8 9相加到一起.

HUH函数
浏览 288回答 2
2回答

扬帆大鱼

var a = document.getElementById("key_n7").value;var b = document.getElementById("key_n8").value;var c = document.getElementById("key_n9").value;var add = document.getElementById("key_na").value;var d = a+add+b+add+c;alert(d);试试这样
随时随地看视频慕课网APP
我要回答