Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 序列化不返回任何内容(输入元素确实有名称…)_Javascript_Jquery_Html_Forms - Fatal编程技术网

Javascript 序列化不返回任何内容(输入元素确实有名称…)

Javascript 序列化不返回任何内容(输入元素确实有名称…),javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,由于某些原因,我无法让jQuery序列化我的表单。在谷歌搜索时,我发现了一堆类似的问题,O.P.忘记给输入一个“名字”。但这不是我的问题,因为我的输入确实有一个名称 $('#time_clock_form').serialize(); 此表单上不返回任何内容 <form id="time_clock_form" method="POST"> <label for="id">Enter last four ligits of SSN<

由于某些原因,我无法让jQuery序列化我的表单。在谷歌搜索时,我发现了一堆类似的问题,O.P.忘记给输入一个“名字”。但这不是我的问题,因为我的输入确实有一个名称

$('#time_clock_form').serialize(); 
此表单上不返回任何内容

<form id="time_clock_form" method="POST">           
    <label for="id">Enter last four ligits of SSN</label>
    <input type="text" id="ssn" name="ssn" maxlength="4">
    <input name="submit" value="Punch Timeclock" type="submit">
</form>

问题是因为在序列化之前禁用了
输入<代码>序列化()
对禁用的表单元素不起作用。更改这些语句的顺序:

$('#ssn').on('input', function() {
    if ($(this).val().length === 4) {
        // serialize the form and store the output here
        console.log($('#time_clock_form').serialize());

        // then disable the form...
        $(this).prop('disabled', true);

        // ajax...
    }
});

输入错误,缺少id选择器:
$('time\u clock\u form')
->
$('time\u clock\u form')
是的,这是一个输入错误。在我的实际代码中,我使用的是ID选择器。实际上,我只是想编辑我的原始问题,在这种情况下,你应该(并且做:)做什么-假设你
serialize()
表单在所有输入都被赋予值时,我用我的serialize代码更新了问题。我已经做过好几次了。我想不出为什么它不起作用,因为它需要更新。我为你补充了一个答案
$('#ssn').on('input', function() {
    if ($(this).val().length === 4) {
        // serialize the form and store the output here
        console.log($('#time_clock_form').serialize());

        // then disable the form...
        $(this).prop('disabled', true);

        // ajax...
    }
});