gpt4 book ai didi

php - 单击按钮时如何显示文本字段?

转载 作者:行者123 更新时间:2023-11-29 23:54:14 25 4
gpt4 key购买 nike

我正在尝试制作一种表单,该表单在加载时仅显示一个文本字段和一个按钮,但是当我们单击该按钮时,它将显示另一个文本字段和其下方的一个按钮,当我们单击该按钮时,它将显示显示三个文本字段和一个按钮,这个最新的按钮将提交表单......这可能吗?......如果可以的话请指导我......这是我的代码......

<div id="envelope">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<center><h1>Edit an existing generic drug</h1></center><br>
<label>Generic Drug Name</label>
<select name = "position" type = "option">
<?php
$query = "SELECT * FROM brand_generic.generic_drug WHERE 1";
$result = mysqli_query($connection, $query);
if(!$result){
die("Database query failed.");
}?><?php
while ($row = mysqli_fetch_assoc($result)) {?>
<option value = "<?php echo $row['generic_drug_name'] ?>"
<?php echo((isset($_POST['position']) && $_POST['position'] == $row['generic_drug_name']) ? 'selected="selected"' : ' ');?>
><?php echo $row['generic_drug_name'];?></option>
<?php }

?>
</select>
<input type="submit" name = "edit" value="Edit" id="submit"/>
<?php
if(isset($_POST['edit'])){ ?>
<label>New Name</label>
<input type="text" name="drug_name" value="<?php echo $_POST['position']; ?>" width="100px;"/>
<input type="submit" name = "submit" value="Submit" id="submit"/>
<?php
if(isset($_POST['submit'])){
$edited_drug_name = $_POST['drug_name'];
echo "Hello world";
}
}

?>
</form>
</div>

当我单击第一个按钮时,它会显示另一个文本字段和按钮,但当我单击新按钮时,它不会回显消息...请帮助

最佳答案

jquery .append应该有帮助。

这是一个例子。

    <script type="text/javascript">
$( function() {
$("#button").click( function(){

var textarea = $("<textarea></textarea>").prop({
name: 'ExampleName'
style: ''
}).addClass( 'classesHere' );

$("form").append(textarea);
})
})
</script>

关于php - 单击按钮时如何显示文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25451032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com