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的优势的解释。
注意isEmail , isAddress , isPostCode等是一个函数名。
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
最满意答案
根据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 onExpressionFactory
.
相关问答
更多-
查看java.lang.Boolean的java文档 。 正如你可以在Constructor Summary部分看到的那样,这个类没有无参数构造函数(这是异常消息所说的)。 您必须: 用boolean或String参数调用它(构造函数) 使用布尔值的默认值 - 这是false 用Boolean.FALSE或Boolean.TRUE初始化该值 View the java docs for java.lang.Boolean. As you can see in the section Constructor ...
-
newInstance()永远不会返回null 。 但newInstance().toString()可以返回"null" 注意:newInstance()的一个问题是它可以抛出CheckedException! public Main() throws IOException { throw new IOException(); } public static void main(String[] args) throws InstantiationException, IllegalAcces ...
-
newInstance在课堂上(newInstance in class)[2022-03-12]
改变这个 addSlide(AppIntroFragment.newInstance(R.string.title_1, R.string.description_1, R.drawable.rateme, R.color.colorPrimaryDark)); 对此 addSlide(AppIntroFragment.newInstance(getString(R.string.title_1), getString(R.string.description_1), R.drawable.rateme, ... -
你的groupId的依赖是错误的。 输入mvnrepository并在那里查找您的依赖项。 com.sun.faces应该是javax.faces(版本号也可能是错的) 如果你从某个博客或网页获得了这种依赖性,试着找出从哪里下载它。 Your groupId's dependency is wrong. Enter mvnrepository and look for your dependencies there. com.sun.faces should be javax.faces (version ...
-
public static
QuestionListFragment newInstance(Bundle args) { // Create a new instance of QuestionListFragment extends Question> QuestionListFragment fragment = new QuestionListFragment (); // Set the ... -
如果您需要存储Object值并愿意接受略有不同的XML输出,则可以从以下位置更改MapEntryType: @XmlAttribute private String key; @XmlValue private Object value; 至: @XmlElement private String key; @XmlElement private Object value; 这将产生如下输出:
someKey 什么是JAXBContext newInstance(String contextPath)?(What is JAXBContext.newInstance(String contextPath)?)[2022-06-18]
解释是在JAXBContext类javadoc中 JAXBContext实例是从冒号分隔的Java包名称列表初始化的。 每个java包都包含JAXB映射类,模式派生类和/或用户注释类。 例: JAXBContext jc = JAXBContext.newInstance( "com.acme.foo:com.acme.bar" ); The explanation is in JAXBContext class javadoc The JAXBContext instance is initialize ...根据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包中找不到此方法也就不足为奇了。 但是这个罐子没有提供这种方法。 所 ...Android Support Maven存储库中缺少DrawerLayout(DrawerLayout is missing in Android Support Maven repository)[2022-03-01]
Maven Central中支持库的最新版本是r7; DrawerLayout在r13中引入。 一种选择是使用SDK附带的jar并将其安装到您当地的maven repo 。 然后,您可以将其作为maven依赖项引用。 The latest release of the support library in Maven Central is r7; DrawerLayout was introduced in r13. One option is to use the jar included with th ...几天前我也遇到过这个问题:它是由报告的JAR破坏引起的(我想在我身边它是由一个这样疯狂的DNS服务器引起的,一些ISP提供的每个请求都以伪造的HTML页面发送给客户端)。 从本地M2缓存中删除maven报告插件并让Maven再次下载它解决了我的问题。 I had this issue also some days ago: It was caused by a broken JAR of reporting (I guess at my side it was caused by one this craz ...相关文章
更多- HTML5服务器事件发送(Server-Sent Events)【HTML5教程 - 第十三篇】
- 两种js function 声明方式
- function-Oceanus配置说明
- HTML5 视频播放事件属性与API控件
- Solr4:Tomcat7与Solr之多核配置(Multiple Cores)
- HTML5 Notification 桌面提醒功能 API
- js事件处理机制及小球移动_HTML5网页游戏坦克大战07
- java 监听redis过期key事件实现延迟队列功能
- HTML5 Geolocation【HTML5教程 - 第十篇】
- HTML5 Drag and Drop【HTML5教程 - 第六篇】
最新问答
更多- 您如何使用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)