Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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_Django - Fatal编程技术网

Javascript 选择器返回未定义的值

Javascript 选择器返回未定义的值,javascript,jquery,django,Javascript,Jquery,Django,HTML <form method="post"> {% csrf_token %} <tr id = "{{ x.id }}"> <td>{{ x.name }}</td> <td>{{ x.sth }}</td> <td>{{ x.sth_else }}</td> <td><button type="

HTML

<form method="post">
    {% csrf_token %}
    <tr id = "{{ x.id }}">
        <td>{{ x.name }}</td>
        <td>{{ x.sth }}</td>
        <td>{{ x.sth_else }}</td>
        <td><button type="submit" name="edit_btn">edit</button></td>
    </tr>
</form>

我试图从html中的tr中提取id,但每当我进入页面并看到控制台输出时,我就会得到:undefined。有什么想法吗?

a
form
和一个
tr
直接孩子?这不是有效的html,可能是您遇到问题的原因a
tr
不是表单的有效子级,因此浏览器会修复您的html,因为它完全无效。你说得对!我换了标签的位置,现在一切都好了。顺便说一句,为什么它是无效的html?因为tr应该是tbody/thead/tfoot的后代,而tbody/thead/tfoot又应该是table的后代,所以它们不属于其他任何地方
$('form').on('submit', function(event){
    event.preventDefault();
    console.log("Executing script for edit button pressing")
    x = $(this).children().first().attr('id');
    console.log(x)
});