0
我有一個Booktitle,Author.I表單,需要驗證這兩個字段,如果它們中的任何一個都是空的,它應顯示消息,因爲字段是強制性的。我做到了這一點。我已經在谷歌搜索了這個,並修改了下面的代碼。如何使用jquery驗證liferay6.1中的表單
<script>
$(document).ready(function() {
$("#_fm").validate();
var element = document.getElementById("_bookTitle");
element.className = element.className + " required";
element = document.getElementById("_author");
element.className = element.className + " required";
});
</script>
<aui:form name="fm" method="POST" action="<%=updateBookURL.toString()%>">
<aui:input name="bookTitle" label="Book Title" />
<aui:input name="author" />
<aui:button type="submit" value="Save" />
</aui:form>
和portlet.xml的是:
<portlet>
<portlet-name>libraryportlet</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portlet-javascript>https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js</header-portlet-javascript>
<header-portlet-javascript>https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js</header-portlet-javascript>
<header-portlet-javascript>
http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js
</header-portlet-javascript>
<footer-portlet-javascript>
/js/main.js
</footer-portlet-javascript>
<css-class-wrapper>libraryportlet-portlet</css-class-wrapper>
</portlet>
但沒有success.Where我做wrong.Can任何人告訴你me.Thank。
我建議你不要使用jquery/javascript進行驗證。 Javascript運行客戶端,很容易禁用。 –