在不加载login.PHP的情况下,如何使用jQuery来检查文本字段是否为空?
<form action="login.PHP" method="post"> <label>Login Name:</label> <input type="text" name="email" id="log" /> <label>Password:</label> <input type="password" name="password" id="pwd" /> <input type="submit" name="submit" value="Login" /> </form>
谢谢.
解决方法
你可以这样做:
// Bind the event handler to the "submit" JavaScript event $('form').submit(function () { // Get the Login Name value and trim it var name = $.trim($('#log').val()); // Check if empty of not if (name === '') { alert('Text-field is empty.'); return false; } });