浏览器之间的表单事件不兼容,该如何解决? [英] Form event incompatibilities between browsers, how to address?

查看:69
本文介绍了浏览器之间的表单事件不兼容,该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html页面上有一个文本区域,在google chrome上,我不知道哪个版本,因为用户界面明显被隐藏了,但是在chrome上,onChange ="code"事件没有触发,但是在Firefox 11.0上1.0(根据help-> about)正在触发.然后,我开始尝试处理事件onkeydown ="same_function()",onpaste ="same_function()"和oninput ="same_function()",以便绝对确保捕获至少一个事件.但是现在的问题是,我收到了太多的事件,并且当我收到按键事件后检查textarea的textarea_dom_object.value时,所读取的值不包括所按下的键;如果我在文本字段中有"abc",然后按"d"键,则会生成一个按键,但是我仍然只得到"abc",而不是"abcd".

I have a textarea on a html page, on google chrome, well I don't know what version because the user interface is deviously hidden, but on chrome the onChange="code" event isn't firing but on Firefox 11.0 1.0 (according to help->about) it is firing. Then instead I start playing around with the events onkeydown="same_function()", onpaste="same_function()" and oninput="same_function()", in order to be absolutely sure to capture at least one event. But now the problem is that I'm getting too many events, and when I check the textarea_dom_object.value of the textarea after getting a keydown event the key that was pressed isn't included in the value that I'm reading; if I have "abc" in the textfield and I press 'd', that generates a keypressed, but I'm still getting only "abc", not "abcd".

是否存在一种兼容的方法,或者至少一种在大多数浏览器上都可以使用的方法,以便在每次文本区域更改时都获得一个事件,但最好只有一个事件?我不喜欢如果必须先测试是否已经听过某个事件等情况,就不得不编写那种难看的代码.每当文本区域中的文本更改时,我想要的只是一个事件.

Is there a compatible way, or at least a way that works on most browsers, to get an event every time a textarea changes, but preferably only one event? I don't like the kind of ugly code I would have to write if I had to first test if I've already listened to an event and so forth. All I want is one event each time the text in the textarea changes.

推荐答案

这就是为什么jQuery如此出色的原因.它了解有必要在不支持较新功能的浏览器之间正常降级代码. JavaScript本身不提供独立支持.通过增强JavaScript在使用jQuery中的核心功能,您通常将在跨浏览器支持下更加成功.

Here's the thing about why jQuery is so amazing. It understands the need to gracefully degrade the code between browsers that don't support newer functionality. JavaScript in and of itself does not offer this support stand alone. By enhancing JavaScript's core capabilities in using jQuery, you are generally going to be more successful with cross browser support.

话虽如此...

在很多情况下,您需要确定要使用的设备/浏览器,以便可以执行预期的操作.

There are still plenty of scenarios where you need to identify what device/browser you're working with so that you can perform the expected operations.

要记住的最重要的事情是,不存在100%的交叉支持库.

The most important thing to remember is that there is no 100% cross-support library in existence.

这篇关于浏览器之间的表单事件不兼容,该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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