我使用JSF,我有一個H:inputText的文本框中,inputText的空管檢查
<h:form>
Please enter your username:
<h:inputText value="#{user.id}"/><br/><br/>
,當用戶按下提交按鈕,我想,
<h:commandButton value="Submit" action="upload/uploadText"/>
爲它檢查在輸入文本框中輸入一個值,並且它的長度超過6個字符
我該怎麼做?
碼我曾嘗試:
<script type="text/javascript">
function required(){
if (document.getElementById("Username").value.length == 0)
{
alert("message");
return false;
}
return true;
}
</script>
與此:
<h:body>
<h:form onsubmit="return required();">
Please enter your username:
<h:inputText id="Username" value="#{user.id}">
</h:inputText><br></br><br></br>
To print a piece of text, please press the submit button below to upload the text:<br/><br/>
<h:commandButton type="submit" value="Submit" action="upload/uploadText"/>
</h:form>
</h:body>
,我仍然感到無法獲得腳本運行
第一步:你看了關於JavaScript驗證? [你有什麼嘗試](http://whathaveyoutried.com)? – epascarello
我已閱讀關於js驗證,我只是不知道它如何檢查只是輸入文本框,郵編上面的代碼我已經試過 – user1924104
這稍微好一點。你打電話給'required'怎麼樣? – epascarello