JavaFX WebView:如何检查表单是否有效? [英] JavaFX WebView: how to check if form is valid?

查看:61
本文介绍了JavaFX WebView:如何检查表单是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过Java判断表单是否有效?

Is there a way to tell if a form is valid from Java?

基本上,如果满足所有输入字段约束,则返回true,否则返回false的方法.

Basically, a method that returns true if all input fields constrains are satisfied and false otherwise.

奇怪的是, org.w3c.dom.html.HTMLFormElement 实际上没有 checkValidity()方法.

Strangely enough, org.w3c.dom.html.HTMLFormElement doesn't actually have a checkValidity() method.

更奇怪的是,实现 com.sun.webkit.dom.HTMLFormElementImpl 确实支持方法 checkValidity().不幸的是,软件包 com.sun.webkit 不能直接访问,因此该方法不可用.

Even more strangely, the implementation com.sun.webkit.dom.HTMLFormElementImpl does support the method checkValidity(). Unfortunately, the package com.sun.webkit is not accessible directly and thus the method is unavailable.

推荐答案

仅HTMLFormElement之类的DOM对象为模型结构.它们无法执行JavaScript.

DOM objects like HTMLFormElement only model structure. They are not capable of executing JavaScript.

但是,WebEngine本身确实具有JavaScript解释器,您可以使用

However, WebEngine itself does have a JavaScript interpreter, which you can invoke using the executeScript method:

boolean valid = (Boolean) webView.getEngine().executeScript(
    "document.forms[0].checkValidity();");

checkValidity()方法已记录在此处.

这篇关于JavaFX WebView:如何检查表单是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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