单击按钮时,jQuery 函数未从 JSF 调用
我有一个 jQuery 文件,其中包含函数。当我的页面加载时,我的脚本就会运行。意味着它被调用。这是我的 jQuery 文件。
(function($){
var $firstPara = $('p').eq(1);
$firstPara.hide();
function checkValidation() {
var labelElementArray = $("label.mandotary");
var inputElementArray = $("input.mandotary");
var selectElementArray = $("select.mandotary");
$.each(inputElementArray, function(index, element){
var text = $(element).text();
}); //end of $.each(inputElementArray, fn)
$.each(selectElementArray, function(index, element) {
////nothing
}); //end of $.each(selectElementArray, fn)
} //end of function checkValidation()
})(jQuery); //end of (function($){}
我有 JSF 表单,其中有按钮。
<h:head>
<title>Facelet Title</title>
<h:outputScript library="javascripts" name="jquery.js" target="body"/>
<h:outputScript library="javascripts" name="validation.js" target="body"/>
</h:head>
<h:body>
<h:form id="validationFrom" >
<h:commandButton id="saveButton"
value="Save"
onclick="checkValidation()"/>
<h:commandButton id="cancelButton"
value="Cancel" />
</h:form >
</h:body>
现在,当我单击“保存”按钮时,它说 checkValidation() 函数未定义。为什么? 我在这里做错了什么?
谢谢
I have a jQuery file with function in it. When my page loads then my script runs. Means it's invoke. Here is my jQuery file.
(function($){
var $firstPara = $('p').eq(1);
$firstPara.hide();
function checkValidation() {
var labelElementArray = $("label.mandotary");
var inputElementArray = $("input.mandotary");
var selectElementArray = $("select.mandotary");
$.each(inputElementArray, function(index, element){
var text = $(element).text();
}); //end of $.each(inputElementArray, fn)
$.each(selectElementArray, function(index, element) {
////nothing
}); //end of $.each(selectElementArray, fn)
} //end of function checkValidation()
})(jQuery); //end of (function($){}
I have JSF form with button in it.
<h:head>
<title>Facelet Title</title>
<h:outputScript library="javascripts" name="jquery.js" target="body"/>
<h:outputScript library="javascripts" name="validation.js" target="body"/>
</h:head>
<h:body>
<h:form id="validationFrom" >
<h:commandButton id="saveButton"
value="Save"
onclick="checkValidation()"/>
<h:commandButton id="cancelButton"
value="Cancel" />
</h:form >
</h:body>
Now when i click on save button, it says that checkValidation() function is undefined. Why?
What i am doing wrong here?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试删除
(function($){
和
})(jQuery); //(函数($){}结束
从js文件中
,而是用这个地方包装你的js代码,
一件事
再编辑
:将其添加到页面的头部,
以便在你的jQuery代码中使用$
try to remove the
(function($){
and the
})(jQuery); //end of (function($){}
from the js file
and instead , wrap your js code with this place the
one more thing
EDIT:
add this in the head of your page
in order to use the $ in your jQuery code
好吧,除了我刚刚进行的少量谷歌搜索之外,我不知道 JSF 是什么,而且我也不熟悉您正在使用的一些 jQuery 语法。假设您可以像处理任何常规旧 html 页面一样处理 JSF 页面,下面是我的做法...
然后删除 JSF 中的 onclick 位。
Welp, I have no idea what JSF is other than the small amount of googling I just did and I'm also not familiar with some of the jQuery syntax you are using. Assuming you can work against a JSF page the same as any regular old html page, here's how I would do it...
Then get rid of your onclick bit in the JSF.