使用javascript创建了提交按钮,该按钮不起作用

时间:2019-05-19 15:35:41

标签: javascript php html

页面加载时,我希望它仅使用标签按顺序显示发布。当用户单击编辑按钮时,它将行的内容更改为文本框和文本区域,以允许用户编辑内容,并将编辑按钮更改为输入的提交。所有标签均已适当更改,但是单击新的“提交”按钮后无任何作用。

我尝试使用editButton.type和editButton.setAttribute()创建属性。我尝试使用type =“ submit”按钮。我看过几篇有关表单操作错误的文章,但是删除按钮仍然可以正常工作,并且操作正确。

这是创建表单的php / html

for($i=0; $i<count($posts); $i++)
            {
                echo '<form onsubmit="return confirmChangePost()" action="../controllers/CRUDController.php" method="POST">';
                    echo '<tr id="'.$i.'">';
                        echo '<td><label name="titleToEdit">'.$posts[$i][2].'</td>';
                        echo '<td><label name="textToEdit" >'.$posts[$i][3].'</label>';
                        echo '<input type="hidden" name="id" value="'.$posts[$i][0].'"/></td>';
                        echo '<td><input type="button" name="edit" value="Edit" onclick="createEditField('.$i.', \''.$posts[$i][2].'\', \''.$posts[$i][3].'\', \''.$posts[$i][0].'\')"></td>';
                        echo '<td><input type="submit" name="delete" value="Delete"/></td>';
                    echo "</tr>";
                echo "</form>";
            }

这是使文本字段和编辑提交的javascript

function createEditField(rowNum, title, text, id)
{
    var rowSelect = document.getElementById(rowNum);
    var td = rowSelect.querySelectorAll('td');
    var titleLabel = td[0].firstChild;
    var textLabel = td[1].firstChild;
    var editButton = td[2].firstChild;

    var titleInput = document.createElement("input");
        titleInput.type = "text";
        titleInput.name = "titleToEdit";
        titleInput.value = title;
    var textInput = document.createElement("textarea");
        textInput.name = "textToEdit";
        textInput.rows = 5;
        textInput.cols = 30;
        textInput.innerHTML = text;
    var editSubmit = document.createElement("input");
        editSubmit.setAttribute("type", "submit");
        editSubmit.setAttribute("name", "edit");
        editSubmit.setAttribute("value", "Edit");

    td[0].replaceChild(titleInput, titleLabel);
    td[1].replaceChild(textInput, textLabel);
    td[2].replaceChild(editSubmit, editButton);
    }

我没有收到任何错误消息。当我单击新的编辑按钮时,应将表单提交给控制器以在数据库中进行更新时,什么都没有发生。

0 个答案:

没有答案