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
insidetd
tag的函数,它使用document.getElementById(“status\u students”).submit()提交表单。