0

我不断得到一个未定义的 val 被传递,并且不知道为什么在表单字段中放置了一些东西。

$('#addNewUserForm input[name="username"]').rules('add', {
    remote: {
        type: 'post',
        url: 'addnewuser/is_username_available',
        data: {
            'username': function() { return $('#username').val(); }
        },
        dataType: 'json'
    }
});
4

1 回答 1

0

Since you're using [name="username"] in your selector, I'll assume that input does not have an ID = "username", which is what you're referencing with $('#username'). Without an ID, should be able to reference the current selector using $(this):

$('#addNewUserForm input[name="username"]').rules('add', {
    remote: {
        type: 'post',
        url: 'addnewuser/is_username_available',
        data: {
            // referencing the current selector
            'username': function() { return $(this).val(); }         },
        dataType: 'json'
    }
});
于 2012-07-17T21:58:28.220 回答