您好我正在尝试制作DOM事件。 当我加载到类的顶部时,我打算初始化一个事件,它将改变我的表单的动作,然后提交表单。
我的代码:
<?php $id = 1 ?>
<html>
<head>
<style>
div.box_images{
background-color:black;
color: white;
margin: 50px 0 50px 0;
padding: 10px;
}
</style>
</head>
<body>
<form name ="form_test" action="test_form2.php" method="post">
<input hidden="hidden" name="id_image" value="<?php echo $id; ?>" >
<div id = "<?php echo $id; ?>" class="box_images" onclick="action_form()">
<h2>IMAGE_<?php echo $id; ?></h2>
<img class="main_img" src="arquivo/fotos/images_<?php echo $id; ?>.jpg">
</div>
</form>
<script>
function action_form(){
document.('form_test').action = "form_upload.php";
document.form_test.submit();
}
</script>
</body>
</html>
甚至需要帮助,我完全被困在这部分代码中。
提前致谢!
答案 0 :(得分:1)
您的语法略有偏差。改变这个
document.('form_test').action = "form_upload.php";
到
document.form_test.action = "form_upload.php";
<form name="form_test" action="test_form2.php" method="post">
<div class="box_images" onclick="action_form()">
<h2>IMAGE_</h2>
</div>
</form>
<script>
function action_form() {
document.form_test.action = "form_upload.php";
console.log(document.form_test.action);
}
</script>
&#13;