javascript - HTML通过点击按钮添加 或删除<input type=.... >

查看:82
本文介绍了javascript - HTML通过点击按钮添加 或删除<input type=.... >的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

我的情况是这样的。如截图

**我想通过点击 添加颜色 按钮实现 添加
<input type... > <select>... 旁边有个删除按钮
也就是说默认的情况下只有 一行<input type... > <select>...**

点击删除按钮,新增的那一行就被删除

代码

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php

$pic[]="很黄.jpg";
$pic[]="很暴力.jpg";
$pic[]="很傻很天真.jpg";

?>
<button id="btn2">添加颜色</button><br><br>
<form action="jq2.php" method="POST">

<input name="product_colour[]" type="text" />
<select name="product_image[]">
<option value="" selected="selected"></option>
<?php
foreach ($pic as $abc){
    
    echo '<option VALUE="'.$abc.'">'.$abc.'</option>';
}
?>
</select>

<br><br>
<button id="btn2">添加</button><br><br>
</form>
</body>
</html>

哪位大神指点一下?

解决方案

顺手给你写了个demo,送分题啊,哈哈。

和php结合起来,只需要用php初始化那个options的数组就行了。

点开查看代码和效果。
https://jsfiddle.net/tbsoyj4k/

这篇关于javascript - HTML通过点击按钮添加 或删除&lt;input type=.... &gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆