简体   繁体   English

第二个JavaScript函数不能与表单标签一起使用

[英]Second JavaScript function is not working with form-tag

I have an issue when using javascript with form tag when I remove <form> all the functions works great, but when I retype It the second function doesn't work. 当我删除<form>时,将JavaScript与表单标记一起使用时,所有功能都很好,但是当我重新键入它时,第二个功能不起作用。

this is the code: 这是代码:

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

any reason for this ? 有什么理由吗? ... and what is the solution ? ...解决方案是什么?

Your tags are out of order, you need to close your table before you close your form. 您的标签混乱,您需要先关闭表格,然后再关闭表单。 Try this: 尝试这个:

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

The problem is the name of JavaScript function "wife_status" the same of HTML element id , changing the name of function or element id will solve the problem . 问题是JavaScript函数“ wife_status”的名称与HTML元素ID相同,更改函数名称或元素ID将解决此问题。 replace "wife_status" function with the following 将“ wife_status”功能替换为以下内容

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM