从jQuery中选择触发onchange的元素

时间:2014-06-26 04:41:37

标签: javascript jquery ajax

我正在尝试创建一个表单,当输入有一个值放入然后是非焦点时它会触发一个事件。

到目前为止,这是我的代码。

$("#live-form input").on('change', function(e) {
    var value = $(this).val();
    var key = $(this).attr("name");
    $.post('update-form.php', {key:value}, function(data) {
        $("#form-status").html(data);
    });
});

我的update-form.php脚本仅返回以下测试响应:

键: - 值:

当我从我的jQuery选择器更改为 #username 时,它工作正常。但除此之外根本没有。

请求的HTML:

<div id="form-status"></div>
<form id="live-form" action="" method="post" autocomplete="off">
    <div class="form-contain">
        <label for="username">Username:</label>
        <input type="text" name="username" id="username" placeholder="Username:" value="" maxlength="32" />
    </div>
</form>

0 个答案:

没有答案
相关问题