您的位置:首页 > Web前端 > JavaScript

JavaScript中属性name与方法名不能相同

2010-11-09 12:27 447 查看
看看以下这段代码对不对,仔细看,你会看出问题。

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabMainBot">
<tr class="trColor">
<td>
<input type="text" name="existOrNotStatus" value="${existOrNotStatus}"/>
<#if existOrNotStatus=="existData">
<input type="button" name="examinAgree" id="examinAgree" value="同意" class="button" onclick="examinAgree()"/>
<#else>
<input type="button" name="examinReport" id="examinReport" class="button" value="上报"/>
</#if>
<input type="button" name="examinDisagree" id="examinDisagree" value="不同意" class="button" onclick="refuseReason()"/>
<input name="Button1" type="button" class="button" value="返回" onclick="history.back(-1)">
</td>
</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabMainBot">
<tbody id="reason" style="display:none;">
<tr class="">
<td width="20%">
拒绝理由:
</td>
<td>
<textarea id="returnBack" name="refuseReason" id="refuseReason" class="textarea" rows="5" readonly>${refuseReason?default("")}</textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="button" name="examinConfirm" id="examinConfirm" value="确定" onclick="examinConfirm()"/>
</td>
</tr>
</tbody>
</table>

找到了吗?有许多name的值与onclick中的方法名是相同的,开始就这样写的,测试代码的时候一直没有任何反应,也不报错,不管用什么浏览器都是一个样子-没有反应,找了半天也不知道是哪儿错了。叫来同事看了看,他也不知道,这时我说,name的值应该不能与onclick的方法名相同,他说可能是,将同名的方法都改成了另外的名字,测试通过。以前总以为,同一个属性的name名与方法不能相同,现在看来是,只要是name名就不能与方法名相同,不管是不是在同一个属性中。

说明了一个问题,起名字很重要,有的时候一不小心就起成关键字了,再有的时候就出现了上面这种情况,没有任何提示的错误,这就是所谓的经验吧。
本文出自 “博客即日起停止更新” 博客,请务必保留此出处http://sucre.blog.51cto.com/1084905/418162
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐