Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 onclick-inside-td标记_Javascript_Jquery_Html_Forms - Fatal编程技术网

javascript onclick-inside-td标记

javascript onclick-inside-td标记,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我想提交一个,里面有。如何使用默认操作提交该?使用标记,我可以提交一个带有onchangejavascript功能的表单。我原以为onclick=“this.form.submit”内的标记可以解决问题,但firebug表示错误:TypeError:this.form未定义 怎么了 <div class="report"> <form method="post" name="status_students"> <table width="100%" bo

我想提交一个
,里面有
。如何使用默认操作提交该
?使用
标记,我可以提交一个带有
onchange
javascript功能的表单。我原以为
onclick=“this.form.submit”
内的
标记可以解决问题,但firebug表示错误:
TypeError:this.form未定义

怎么了

<div class="report">
  <form method="post" name="status_students">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="tdreport">Active</td>
        <td class="tdreport">Unstable</td>
        <td class="tdreport">Inactive</td>
      </tr>
      <tr>
        <td class="active" name="students_actives" value="actives" onclick="this.form.submit()">
          <?php
          if ($this->siteCenterSelected == "All") {
          echo count($this->usersStatus['verde']);
          } else {
          echo count($this->usersStatusSiteCenter['verde']);
          }
          ?>
        </td>
        <td class="unstable"><?php
          if ($this->siteCenterSelected == "All") {
          echo count($this->usersStatus['amarelo']);
          } else {
          echo count($this->usersStatusSiteCenter['amarelo']);
          }
          ?>
        </td>
        <td class="inactive"><?php
          if ($this->siteCenterSelected == "All") {
          echo count($this->usersStatus['vermelho']);
          } else {
          echo count($this->usersStatusSiteCenter['vermelho']);
          }
          ?>
        </td>
      </tr>
    </table>
  </form>
</div>

活跃的
不稳定
不活跃的

您在onclick函数中引用的这个
对象是单击的
td
,而不是整个文档。您可能希望改用此选项:

onclick="document.forms[0].submit()"

但实际上,您最好通过其ID来引用表单。

在您的场景中,引用td元素时,一个快速而肮脏的解决方案是使用
.parent
->
this.parent.parent
进入dom。你也可以通过他的名字找到你的表格
document.status\u students
尝试
document.status\u students.submit()
!请注意,如果您有多个表单,请更改索引,因为
[0]
表示第一个表单元素。非常感谢。事实上,我已经创建了一个名为
onclick
inside
td
tag的函数,它使用
document.getElementById(“status\u students”).submit()提交表单。