下拉框增加刪除

界面


運(yùn)行結(jié)果


表頭部分

<link rel="shortcut icon" href="favicon.ico"> <link href="../css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">

? ? <link href="../css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

? ? <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">

? ? <link href="../css/animate.min.css" rel="stylesheet">

? ? <link href="../css/style.min862f.css?v=4.1.0" rel="stylesheet">

主體部分

HTML

<div class="ibox-content col-sm-3">

? ? <div class="form-group">

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <div class="col-sm-7">

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <select class="form-control" id="sel">

? <option>燈泡</option>

? <option>鎖</option>

? <option>拖把</option>

? <option>螺絲</option>

? <option>電線</option>

</select>

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </div> <label class="col-sm-4 control-label">? <button? class="btn btn-primary" id="add_row">添加行</button></label>

? ? ? ? ? ? ? ? ? ? ? ? ? ? </div>

<table? class="table">

<tbody id="test">

</tbody>

</table>

</div>

? ? ? ? <table style="display: none;">

? ? ? ? ? ? <tbody id="modo">

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? </tbody>

? ? ? ? </table>

JQ代碼

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

? ? ? ? <script>

? ? ? ? ? ? //var a = $("#test").children().length;

? ? ? ? ? ? //alert(a)

? ? ? ? ? ? $("#add_row").click(add_row)

? ? ? ? ? ? function add_row() { //添加行方法

? ? ? ? ? ? ? ? var mode_tr = $("#modo tr:first").clone();

? ? ? ? ? ? ? ? var selStr=$("#sel").val();

var td1= $("<td>"+selStr+"</td>").addClass("td_up");

? ? var td2 = $("<td><input type='text'/></td>").addClass("td_up");

var td3=$("<td><i class='fa? fa-times? text-navy' id='dele_row' onclick='dele_row(this)'></i></td>");

$("#test").append(mode_tr);

$(mode_tr).append(td1);

$(mode_tr).append(td2);

$(mode_tr).append(td3);

? ? ? ? ? ? }

? ? ? ? ? ? function dele_row(obj) {

? ? ? ? ? ? ? ? $(obj).parent().parent().remove();

? ? ? ? ? ? }

? ? ? ? </script>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容