我不知道爲什麼我的代碼不工作,控制檯中沒有錯誤信息。 在驗證規則內的屬性名是否引用輸入表單的id或名稱? 該庫已正確包含在一般的html模板中,並且$("#form").validate
中的警報正常工作。jQuery驗證無法正常工作
的Javascript:
$(document).ready(function()
{
$("#form").validate(alert("ciaoo"), //this alert works fine
{
rules:
{
nome: "required"
},
messages:
{
nome: " Inserisci il tuo nome!"
}
});
});
HTML:
<form id="form" action="Inserisci_Utente" method="post" >
<fieldset>
<legend>Registrazione Utente</legend>
<#if (messaggio??)>
<#if (success??)>
<div class="successo"><img src="img/success.png"/> <span>Operazione completata con successo.</span>
<ul>
<#list messaggio as mex>
<li>${mex?html?lower_case?cap_first?trim} </a> </li>
</#list>
</ul>
</div>
<#else>
<div class="errore"><span></span>
<ul>
<#list messaggio as mex>
<li>${mex?html?lower_case?cap_first?trim} </a> </li>
</#list>
</ul>
</div>
</#if>
</#if>
<div class="fieldset">
<fieldset>
<label>Nome</label>
<input type="text" id ="nome" name="nome"/>
<label>Cognome</label>
<input type="text" name="cognome" />
</fieldset>
<fieldset>
<label>Mail</label>
<input type="text" name="mail" class="mail"/>
</fieldset>
</div>
<div class="fieldset">
<fieldset>
<label>Username</label>
<input type="text" name="username"/>
</fieldset>
<fieldset>
<label>Password</label>
<input type="password" name="pass1"/>
<label>Ripeti la password</label>
<input type="password" name="pass2"/>
</fieldset>
<fieldset>
<label>Ruolo</label>
<input type="radio" name="ruolo" value="amministratore"/>Amministratore
<input type="radio" name="ruolo" value="organizzatore"/>Organizzatore<br>
</fieldset>
</div>
<fieldset>
<input type="submit" name="registra" value="Registrami"/>
</fieldset>
</fieldset>
</form>
本來也最好能展現_rendered_ HTML瀏覽器,而不是您的原始未呈現的HTML文件可見。 – Sparky