第二个JavaScript函数无法使用表单标记

第二个JavaScript函数无法使用表单标记,javascript,forms,Javascript,Forms,我在使用带有表单标记的javascript时遇到了一个问题 当我删除时,所有函数都工作得很好,但当我重新键入时,第二个函数就不工作了 代码如下: <?php require_once('../db.php'); require_once('operationsAPI.php'); ?> <html> <head><title>::family card::</title><meta charset='utf-8'> <

我在使用带有表单标记的javascript时遇到了一个问题 当我删除
时,所有函数都工作得很好,但当我重新键入时,第二个函数就不工作了

代码如下:

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

::家庭卡:
功能状态(str){
如果(str!=“父亲信息”){
document.getElementById('father_status').setAttribute(“disabled”、“disabled”);
document.getElementById('father_status').setAttribute(“样式”,“背景:#dddddd;宽度:100%”);
document.getElementById('father_health_status').setAttribute(“disabled”、“disabled”);
document.getElementById('father_health_status').setAttribute(“样式”,“背景:#dddddddd;宽度:100%;”);
document.getElementById('father_health_note').setAttribute(“disabled”、“disabled”);
document.getElementById('father_health_note').setAttribute(“样式”,“背景:#dddddddd;宽度:100%);
}否则{
document.getElementById('father_status')。removeAttribute(“disabled”);
document.getElementById('father_status').setAttribute(“样式”,“宽度:100%;”);
document.getElementById(“父亲健康状况”).removeAttribute(“禁用”);
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%”);
}
}
功能状态(str){
如果(str!=“母亲信息”){
document.getElementById(“妻子状态”).setAttribute(“已禁用”、“已禁用”);
document.getElementById('fixer_status').setAttribute(“样式”,“背景:#dddddd;宽度:100%”);
document.getElementById(“妻子健康状况”).setAttribute(“已禁用”、“已禁用”);
document.getElementById(“妻子健康状况”).setAttribute(“样式”,“背景:#dddddd;宽度:100%;”;
document.getElementById('fixer_health_note').setAttribute(“disabled”、“disabled”);
document.getElementById('fixer_health_note').setAttribute(“样式”,“背景:#dddddddd;宽度:100%);
}否则{
document.getElementById(“妻子身份”).removeAttribute(“禁用”);
document.getElementById(“妻子状态”).setAttribute(“样式”,“宽度:100%;”);
document.getElementById(“妻子健康状况”).removeAttribute(“禁用”);
document.getElementById(“妻子健康状况”).setAttribute(“样式”,“宽度:100%”);
document.getElementById(“妻子健康注释”).removeAttribute(“禁用”、“禁用”);
document.getElementById('fixer_health_note').setAttribute(“style”,“width:100%”);
}
}

有什么原因吗。。。解决方案是什么?

您的标签出现问题,需要先关闭表格,然后再关闭表单。试试这个:

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

问题在于JavaScript函数“妻子状态”的名称与HTML元素id的名称相同,更改函数或元素id的名称将解决问题。将“妻子状态”功能替换为以下内容

 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%;");
        }
    }

这是你所有的代码吗?您的表单标记中有任何内容吗?是否关闭表单标记?主题:为什么有这么多相同的文档。getElementById。。。你为什么不把它赋给一个变量呢?不,它是它的一部分,我只有一个表单标签,是的,我关闭了它。你在任何地方调用这些函数吗?你不认为我们需要看看你是如何用它们来诊断它们的吗?我同意克里斯威拉德的观点。您是否在控制台中看到任何错误?