在做个计算器,用表格做的,直接给整个表格添加点击事件来获取相应的td内容,但是获取不到啊,求大神帮忙看看。
results直接赋值在id="display"那个格子能显示出来,就是那个event事件获取innerText获取不了。。。
<script type="text/javascript">
var results = " "; // 算式
var calresult = " "; //计算结果
function calculater() {
if (event.srcElement.innerText == "=") {
return;
}
if (event.srcElement.innerText == "C") { // C清除
results = " "; display.innerText = "0"; return;
}
results += event.srcElement.innerText; //算式累加
display.innerText = results;
}
function resultscalcaulte() { //结果
calresult = eval(results);
display.innerText = calresult;
}
</script>
<table id="calcuater" onclick="calculater()">
<tr>
<td id="display" colspan="5">0</td>
</tr>
<tr>
<td class="numberkey">1</td>
<td class="numberkey">2</td>
<td class="numberkey">3</td>
<td class="numberkey">+</td>
<td class="numberkey" id="deletesign">C</td>
</tr>
<tr>
<td class="numberkey">4</td>
<td class="numberkey">5</td>
<td class="numberkey">6</td>
<td class="numberkey">-</td>
<td rowspan="3" id="equality" onclick="resultscalcaulte()">=</td>
</tr>
<tr>
<td class="numberkey">7</td>
<td class="numberkey">8</td>
<td class="numberkey">9</td>
<td class="numberkey">*</td>
</tr>
<tr>
<td class="numberkey">+/-</td>
<td class="numberkey">0</td>
<td class="numberkey">.</td>
<td class="numberkey">/</td>
</tr>
</table>
function calculater(event){
var $tgt = $(event.target);
}
这个没有看出来