こんにちは、次は私のログインフォームです。ユーザーがuserNameフィールドに8文字を入力できないように制限したいのですが、次のコードは機能していません:
<div data-role="content">
<form id="loginForm">
<div data-role="fieldcontain" class="ui-field-contain ui-body ui-br">
<label for="username">Username:</label> <input type="text"
name="username" id="username" value="" maxlength="8" /> <label for="password">Password:</label>
<input type="password" name="password" id="password" value="" /> <label
for="dob">Date of birth:</label> <input type="password"
type="password" name="dob" id="dob" value="" />
</div>
<div >
<fieldset class="ui-grid-a" >
<div class="ui-block-a" >
<input type="submit" data-role="button" value="Login"
id="submitButton">
</div>
<div class="ui-block-b">
<input type="reset" data-role="button" value="Cancel"
id="cancelButton">
</div>
</fieldset>
</div>
</form>
</div>
<script type="text/javascript">
</script>
<script type="text/javascript">
$("#username").live('keydown', function (event)
{
if ((event.keyCode.length>8))
{
event.preventDefault();
}
});
</script>
ただし、ユーザーは UserName フィールドに任意の数の文字を入力できます。このコードで何が間違っていますか? 任意の提案をいただければ幸いです。前もって感謝します