按钮OnClick事件在导致文本框onChange事件首先触发时不会触发 [英] Buttons OnClick Event not firing when it causes a textboxes onChange event to fire first

查看:390
本文介绍了按钮OnClick事件在导致文本框onChange事件首先触发时不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个文本框和按钮,用于在网页上保存其值。文本框的onchange事件触发一些js,它们将更改的文本添加到js数组中。单击时,ok按钮会通过Web服务将其刷新到数据库。当通过单击确定按钮导致onchange事件时,此工作正常。在这种情况下,文本框的onchange仍然会触发,但按钮的onClick事件不会触发。有什么想法?

I have a few textboxes and button to save their values on a webpage. The onchange event of the textboxes fires some js which adds the changed text to a js array. The ok button when clicked flushes this to the database via a webservice. This works fine except when the onchange event is caused by clicking the ok button. In this scenario the onchange of the textboxes still fires but the onClick event of the button does not. Any ideas?

文本框看起来像

<input name="ctrlJPView$tbcTabContainer$Details$JP_Details_Address2Text" type="text" value="test" 
id="ctrlJPView_tbcTabContainer_Details_JP_Details_Address2Text" onchange="addSaveDetails('Jobs###' +    document.getElementById('ctrlJPView_tbcTabContainer_Details_JP_Details_Address2Text').value + ');" style="font-size:8pt;Left:110px;Top:29px;Width:420px;Height:13px;Position:absolute;" />

我的保存按钮

<input type="button" name="ctrlJPView$btnOk" value="OK" onclick="saveAmendments();refreshJobGrids();return false;__doPostBack('ctrlJPView$btnOk','')" id="ctrlJPView_btnOk" class="ControlText" style="width:60px;" />

更新:我想这归结为两件事之一。 1)在按钮的onClick被调用之前发生了一些事情来压制那些无意中返回false的调用;或2)onClick事件根本没有触发。现在我已经预先调出了事先调用的函数中的所有内容,但问题仍然存在。但如果我完全删除了它的调用它(???)

UPDATE: I guess this comes down to one of two things. 1) Something is happening before the onClick of the button gets called to surpress that call such as an inadvertent return false; or 2) the onClick event isn't firing at all. Now I've rem'd out everything actually inside the functions that are being called beforehand but the problem persists. But if i remove the call altogether it works (???)

推荐答案

__ doPostBack 运行一个无法执行的功能?在这种情况下,返回false 是一个明显的问题 - 一旦你返回,就不会有更多的代码被执行。

is the __doPostBack function the one failing to execute? in this case, the return false is the obvious problem - once you return, no more code gets executed.

在一个更迂腐的说明中,你应该真的停止在你的html中使用onBlah处理程序,而是使用一个提供事件观察者的现代javascript库。我建议 jquery ,但 extjs 原型也可以通过其他方式让你的生活变得更轻松。

on a more pedantic note, you should really stop using onBlah handlers in your html, and instead use a modern javascript library that provides event observers. i recommend jquery but extjs or prototype would also work and make life much easier for you in a thousand other ways.

这篇关于按钮OnClick事件在导致文本框onChange事件首先触发时不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆