首页 \ 问答 \ HTML多个事件触发相同的功能(HTML multiple events to trigger the same function)

HTML多个事件触发相同的功能(HTML multiple events to trigger the same function)

有没有办法让多个事件( 例如oninput,onblur )在HTML中触发完全相同的功能?

这是我试图简化的HTML:

<input id="Email" name="Email" type="text" oninput="toggleSuccessIcon(this, isEmail)" onblur="toggleSuccessIcon(this, isEmail)">

我知道这在jQuery中是可能的,如此处所解释的,但由于我有很多不同的输入( 例如地址,邮政编码等 )需要调用不同的函数(例如toggleSuccessIcon(this,isAddresss),toggleSuccessIcon(this,isPostCode)等等。我想避免在JavaScript中进行冗长而混乱的初始化。 但是,如果我在HTML而不是JQuery中这样做是愚蠢的,我会理解使用JQuery的优势的解释。

注意isEmailisAddressisPostCode等是一个函数名。


Is there a way to have multiple events (e.g. oninput, onblur) trigger exactly the same function in the HTML?

This is the HTML that I'm trying to simplify:

<input id="Email" name="Email" type="text" oninput="toggleSuccessIcon(this, isEmail)" onblur="toggleSuccessIcon(this, isEmail)">

I know this is possible in jQuery as explained here, but since I have a lot of different inputs (e.g. address, postcode, etc.) that need to call different functions (e.g. toggleSuccessIcon(this, isAddresss), toggleSuccessIcon(this, isPostCode), etc.) I wanted to avoid having a long and messy initialisation in the JavaScript. However, if I am being foolish by doing this in HTML rather than JQuery I'd appreciate an explanation as to the advantage of using JQuery.

Note that isEmail, isAddress, isPostCode, etc. is a function name.


原文:https://stackoverflow.com/questions/29789202
更新时间:2023-10-09 11:10

最满意答案

根据java ee 5 api, ExpressionFactory提供了一个方法#newInstance

好吧,javadoc不是证明,实际上,这很可能是Java EE 5 javadoc中的一个错误。 在JSR-245维护评论1中添加了两个newInstance()工厂方法(使EL独立并从JSP 2.1中取出,详细了解JSR-245 MR1更改日志 )但是评论从未发布过

因此,在java.net repo中可用的java-ee包中找不到此方法也就不足为奇了。

但是这个罐子没有提供这种方法。 所以我得到了编译错误。

正如所料。 这个方法不在Java EE 5中(至少这是我的理解)。 所以你需要使用:

ExpressionFactory factory = new ExpressionFactoryImpl();

maven(java.dev.net)提供的官方Java EE 6.0 jar包含此方法。

是的,因为这是Java EE 6,因为EL现在是独立的,有自己的规范(从技术上讲,EL仍然在JSR-245中,如果这令人困惑,很抱歉)。 所以Java EE 6包含了EL 2.2(是的,版本从1.1跳到2.1.2然后是2.2,以便更好地与JSP版本保持一致)。 这个版本确实暴露了ExpressionFactory上的newInstance()方法。


According to java ee 5 api ExpressionFactory provides a method #newInstance.

Well, javadoc is not a proof and, actually, this is very likely an error in the Java EE 5 javadoc. The two newInstance() factory methods have been added in the Maintenance Review 1 of the JSR-245 (to make EL standalone and take it out of JSP 2.1, have a look at the JSR-245 MR1 Change Log for the details) but that review has never been released.

So it's not surprising that you don't find this method in the java-ee bundle available in the java.net repo.

But this jar does not provide this method. So I get compiler errors.

As expected. This method is not in Java EE 5 (at least this is my understanding). So you need to use:

ExpressionFactory factory = new ExpressionFactoryImpl();

The official Java EE 6.0 jar provided by maven (java.dev.net) contains this method.

Yes, because this is Java EE 6, because EL is now standalone, with its own specification (technically, EL is still in JSR-245, sorry if this is confusing). So Java EE 6 includes EL 2.2 (yes, the version jumped from 1.1 to 2.1.2 and then 2.2 for a better alignment with the JSP version). And this version does expose the newInstance() methods on ExpressionFactory.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)