我見過很多相關的帖子,但這裏沒有任何東西在爲我工作。 所以在這裏,我試圖驗證每個按鍵上的輸入數據,並在下一個div(在下一個單元格)中顯示錯誤,嘗試了許多遍歷組合,但沒有運氣。下面表格單元遍歷jQuery
代碼給出: -
$(this).keypress(function() {
//alert(this);
if (($(this).val().length < 5)||($(this).val().length > 20)) // maybe not working
$(this).parent('td').next('td').children('div').text("Error"); // <- not working
// check input for validity here
});
表: -
<table width="1032" height="448" align="center" cellpadding="1" cellspacing="0">
<tr>
<th width="153" align="right" scope="row"><strong>Name:</strong></th>
<td width="420">
<label for="user_name"></label>
<input name="user_name" type="text" id="user_name" size="70" maxlength="100" value="<?php if (isset($row)) echo $row[1]; ?>"/>
</td>
<td width="451">
<div id="div_user_name"></div>
</td>
</tr>
</table>
修正if語句 – SAQIBZAFAR 2012-02-09 07:37:40
我們有走!檢查我最新的編輯與jsfiddle的例子,工作好... :) – 2012-02-09 07:39:44