1

这是我的表格,

<form action="" method="post" id="signupform">
    <input class="email" id="email"  type="email" placeholder="somebody@example.com" />
    <input type="submit" value="submit"/>
</form>

这是javascript,

$(document).ready(function(){
    $('#signupform').submit(function(){
         return valid_email();
});
});



function valid_email(){
    var email = $('#signupform > #email ').val();
    alert(email);
    return false;
}

它会提醒“未定义”,但如果我使用,只有$('#email'),我会得到正确的值。我在哪里犯错。

4

1 回答 1

1

Assign initial value to the textbox then you will be able to get it the placeholder is not taken by val() and show empty.

Live Demo

$(document).ready(function() {
    $('#signupform').submit(function() {
        return valid_email();
    });
});

function valid_email() {
    var email = $('#signupform > #email ').val();
    alert(email);
    return false;
}​
于 2012-11-17T08:28:43.373 回答