使用带有表单标记的javascript时出现问题
当我删除<form>
时,所有函数都运行良好,但是当我重新键入它时,第二个函数不起作用。
这是代码:
<?php
require_once('../db.php');
require_once('operationsAPI.php');
?>
<html>
<head><title>::family card::</title><meta charset='utf-8'>
<script>
function beneficial_status(str) {
if (str != 'father_info') {
document.getElementById('father_status').setAttribute("disabled", "disabled");
document.getElementById('father_status').setAttribute("style", "background:#dddddd;width:100%;");
document.getElementById('father_health_status').setAttribute("disabled", "disabled");
document.getElementById('father_health_status').setAttribute("style", "background:#dddddd;width:100%;");
document.getElementById('father_health_note').setAttribute("disabled", "disabled");
document.getElementById('father_health_note').setAttribute("style", "background:#dddddd;width:100%;");
} else {
document.getElementById('father_status').removeAttribute("disabled");
document.getElementById('father_status').setAttribute("style", "width:100%;");
document.getElementById('father_health_status').removeAttribute("disabled");
document.getElementById('father_health_status').setAttribute("style", "width:100%;");
document.getElementById('father_health_note').removeAttribute("disabled", "disabled");
document.getElementById('father_health_note').setAttribute("style", "width:100%;");
}
}
function wife_status(str) {
if (str != 'mother_info') {
document.getElementById('wife_status').setAttribute("disabled", "disabled");
document.getElementById('wife_status').setAttribute("style", "background:#dddddd;width:100%;");
document.getElementById('wife_health_status').setAttribute("disabled", "disabled");
document.getElementById('wife_health_status').setAttribute("style", "background:#dddddd;width:100%;");
document.getElementById('wife_health_note').setAttribute("disabled", "disabled");
document.getElementById('wife_health_note').setAttribute("style", "background:#dddddd;width:100%;");
} else {
document.getElementById('wife_status').removeAttribute("disabled");
document.getElementById('wife_status').setAttribute("style", "width:100%;");
document.getElementById('wife_health_status').removeAttribute("disabled");
document.getElementById('wife_health_status').setAttribute("style", "width:100%;");
document.getElementById('wife_health_note').removeAttribute("disabled", "disabled");
document.getElementById('wife_health_note').setAttribute("style", "width:100%;");
}
}
</script>
</head>
<body>
<form action="test2.php" method="get">
<?
$table = hc_empty_family_info_table();
echo '<table align="center" border="1" dir="rtl">';
foreach($table as $values)
{
echo $values;
}
?>
</form>
</table>
</body>
</html>
任何原因? ......什么是解决方案?
答案 0 :(得分:0)
您的代码无序,您需要在关闭表单之前关闭桌面。试试这个:
<form action="test2.php" method="get">
<?
$table = hc_empty_family_info_table();
echo '<table align="center" border="1" dir="rtl">';
foreach($table as $values)
{
echo $values;
}
?>
<!-- these two tags are switched -->
</table>
</form>
答案 1 :(得分:0)
问题是JavaScript函数的名称&#34; wife_status&#34;与HTML元素id相同,更改函数名称或元素id将解决问题。替换&#34; wife_status&#34;具有以下功能
function wife_status(str) {
if (str != 'mother_info') {
document.getElementById('wife_status').setAttribute("disabled", "disabled");
document.getElementById('wife_status').setAttribute("style", "background:#dddddd;width:100%;");
document.getElementById('wife_health_status').setAttribute("disabled", "disabled");
document.getElementById('wife_health_status').setAttribute("style", "background:#dddddd;width:100%;");
document.getElementById('wife_health_note').setAttribute("disabled", "disabled");
document.getElementById('wife_health_note').setAttribute("style", "background:#dddddd;width:100%;");
} else {
document.getElementById('wife_status').removeAttribute("disabled");
document.getElementById('wife_status').setAttribute("style", "width:100%;");
document.getElementById('wife_health_status').removeAttribute("disabled");
document.getElementById('wife_health_status').setAttribute("style", "width:100%;");
document.getElementById('wife_health_note').removeAttribute("disabled", "disabled");
document.getElementById('wife_health_note').setAttribute("style", "width:100%;");
}
}