[Javascript问题]Jquery使用中遇到的小问题 望不吝赐教

Wicho开源开发中 2012-12-17 10:26:44

window.onfocus = function(){
$(":input[id^='btnOpration']").each(function(){
$(this).click(function(){
var val = $(":input[id$='txtExpressions']").val();
switch($(this).val())
{
case "←":
$(":input[id$='txtExpressions']").val(val.length>0?val.substring(0,val.length-1):"");
break;
case "CE":
$(":input[id$='txtExpressions']").val("");
break;
case "等于":
$(":input[id$='txtExpressions']").val(val+"=");
break;
case "小于":
$(":input[id$='txtExpressions']").val(val+"<");
break;
case "大于":
$(":input[id$='txtExpressions']").val(val+">");
break;
default:
//alert($(this).val());
$(":input[id$='txtExpressions']").val(val+(isField($(this).val())?"["+$(this).val()+"]":$(this).val()));
break;
}
});
});
}

function isField(val)
{
var params = new Array("0","1","2","3","4","5","6","7","8","9","+","-","*","/",".","(",")");
params = params.join(",");
if(params.indexOf(val)>=0)
{
return false;
}
return true;
}



<table cellpadding="0" cellspacing="0" border="1" width="98%" class="tablesort" style="MARGIN-TOP:0px;MARGIN-BOTTOM:0px">
<tr>
<td width="75%" style="MARGIN-LEFT:10px">
<asp:TextBox ID="txtExpressions" Runat="server" TextMode="MultiLine" Width="100%" Rows="6"></asp:TextBox></td>
<td style="VERTICAL-ALIGN:top">
<table class="opration">
<tr>
<td><input type="button" id="btnOpration10" value="1"></td>
<td><input type="button" id="btnOpration11" value="2"></td>
<td><input type="button" id="btnOpration12" value="3"></td>
<td><input type="button" id="btnOpration13" value="+"></td>
<td><input type="button" id="btnOpration14" value="←"></td>
</tr>
<tr>
<td><input type="button" id="btnOpration20" value="4"></td>
<td><input type="button" id="btnOpration21" value="5"></td>
<td><input type="button" id="btnOpration22" value="6"></td>
<td><input type="button" id="btnOpration23" value="-"></td>
<td rowspan="4" class="maxButton"><input type="button" id="btnOpration24" value="CE" style="HEIGHT:100%"></td>
</tr>
<tr>
<td><input type="button" id="btnOpration30" value="7"></td>
<td><input type="button" id="btnOpration31" value="8"></td>
<td><input type="button" id="btnOpration32" value="9"></td>
<td><input type="button" id="btnOpration33" value="*"></td>
</tr>
<tr>
<td><input type="button" id="btnOpration40" value="0"></td>
<td><input type="button" id="btnOpration41" value="."></td>
<td><input type="button" id="btnOpration42" value="等于"></td>
<td><input type="button" id="btnOpration43" value="/"></td>
</tr>
<tr>
<td><input type="button" id="btnOpration50" value="小于"></td>
<td><input type="button" id="btnOpration51" value="大于"></td>
<td><input type="button" id="btnOpration52" value="("></td>
<td><input type="button" id="btnOpration53" value=")"></td>
</tr>
</table>
</td>
</tr>
</table>



INPUT { BORDER-BOTTOM: #eee 1px groove; BORDER-LEFT: #eee 1px groove; BACKGROUND-COLOR: #f0f8ff; COLOR: blue; BORDER-TOP: #eee 1px groove; BORDER-RIGHT: #eee 1px groove }
.opration TD { WIDTH: 50px }
.opration INPUT { WIDTH: 100%; HEIGHT: 20px }
.rewidth TD { WIDTH: 150px }
.rewidth INPUT { WIDTH: 100%; HEIGHT: 20px }
.maxButton { HEIGHT: 100% }
...全文
417 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱在夕阳下 2012-12-21
  • 打赏
  • 举报
回复
js错误 有时调试一下 很快就发现问题出哪里了,,
angle860123 2012-12-21
  • 打赏
  • 举报
回复
积累js知识中。。。。。。。
风2013 2012-12-21
  • 打赏
  • 举报
回复
其实吧 你应该先清掉$(":input[id$='txtExpressions']").val("");的值 然后在去执行循环累加的 把上面那句话加到第一行 你那个onfocs不保险 一般鼠标的移进去移出来很正常的 每次都在叠加 重复了也正常
yzf86211861 2012-12-21
  • 打赏
  • 举报
回复
这个知识点 学到了
  • 打赏
  • 举报
回复
继续积楼 结贴
段传涛 2012-12-20
  • 打赏
  • 举报
回复
focus 用的时候还是要注意的。 搞明白就好。
net_HCC 2012-12-20
  • 打赏
  • 举报
回复
引用 11 楼 net_HCC 的回复:
引用 2 楼 shwicho 的回复:顶一下 引用 10 楼 shwicho 的回复:6楼的以下都没错 确实是 focus的问题 顶一下
0
net_HCC 2012-12-20
  • 打赏
  • 举报
回复
引用 2 楼 shwicho 的回复:
顶一下
引用 10 楼 shwicho 的回复:
6楼的以下都没错 确实是 focus的问题
顶一下
  • 打赏
  • 举报
回复
6楼的以下都没错 确实是 focus的问题
残月照我心 2012-12-18
  • 打赏
  • 举报
回复
引用 7 楼 yw39019724 的回复:
你把方法写在 window.onfocus 中,每次你的按钮获得焦点时都会触发。
+++
  • 打赏
  • 举报
回复
再顶一次
  • 打赏
  • 举报
回复
不是这个问题 是点击按钮一次 有时候会出现 1到多次重复值
  • 打赏
  • 举报
回复
两次提交 一种状况会发生在<button/> 标签,而且仅在IE8下会出现,因为IE8下默认 type="submit",这时,只要明确指明type类型就可以 而另一种情况,可能是用户在请求未处理完毕之前,连续点击提交所致,那么,可以用户点击之后,锁定,请求完成,在解锁即可.
  • 打赏
  • 举报
回复
顶一下
  • 打赏
  • 举报
回复
问题是 按钮点击 有时候会出现多次重复值
v_yao 2012-12-17
  • 打赏
  • 举报
回复
所以你会得到多次的值
v_yao 2012-12-17
  • 打赏
  • 举报
回复
你把方法写在 window.onfocus 中,每次你的按钮获得焦点时都会触发。
事理 2012-12-17
  • 打赏
  • 举报
回复
有可能是window.onfocus =的问题,改成这个试试 $(function(){ $(":input[id^='btnOpration']").each(function(){ $(this).click(function(){ var val = $(":input[id$='txtExpressions']").val(); switch($(this).val()) { case "←": $(":input[id$='txtExpressions']").val(val.length>0?val.substring(0,val.length-1):""); break; case "CE": $(":input[id$='txtExpressions']").val(""); break; case "等于": $(":input[id$='txtExpressions']").val(val+"="); break; case "小于": $(":input[id$='txtExpressions']").val(val+"<"); break; case "大于": $(":input[id$='txtExpressions']").val(val+">"); break; default: //alert($(this).val()); $(":input[id$='txtExpressions']").val(val+(isField($(this).val())?"["+$(this).val()+"]":$(this).val())); break; } }); }); });

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧