Javascript的onclick在td标签内

javascript onclick inside td tag

本文关键字:标签 td onclick Javascript      更新时间:2023-09-26

我想提交一个包含<table><form>。如何提交具有默认动作的<form> ?与<select>标签,我可以提交一个表单与onchange javascript函数。我认为<td>标签内的onclick="this.form.submit"会解决,但firebug指示错误:TypeError: this.form is undefined

怎么了?

<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>

this对象,您在onclick函数中引用的是单击的td,而不是整个文档。你可能想用这个代替:

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