国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery實現動態添加、刪除按鈕及input輸入框的方法

2024-05-06 15:46:05
字體:
來源:轉載
供稿:網友

我們在開發項目的時候都需要使用jQuery進行開發,那么jQuery要如何實現動態添加、刪除按鈕及input輸入框的方法呢?今天就讓錯新技術頻道小編和大家分享吧!

<html><head><meta charset="utf-8"><title>動態創建按鈕</title><script src='http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js'></script></head><body><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="AddMoreFileBox" class="btn btn-info">添加更多的input輸入框</a></span></p><div id="InputsWrapper"><div><input type="text" name="mytext[]" id="field_1" value="Text 1"/><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="removeclass"><input type='button' value='刪除'></a></div></div><script>$(document).ready(function() {var MaxInputs    = 8; //maximum input boxes allowedvar InputsWrapper  = $("#InputsWrapper"); //Input boxes wrapper IDvar AddButton    = $("#AddMoreFileBox"); //Add button IDvar x = InputsWrapper.length; //initlal text box countvar FieldCount=1; //to keep track of text box added$(AddButton).click(function (e) //on add input button click{    if(x <= MaxInputs) //max input box allowed    {      FieldCount++; //text box added increment      //add input box      $(InputsWrapper).append('<div><input type="text" name="mytext[]" id="field_'+ FieldCount +'" value="Text '+ FieldCount +'"/><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="removeclass"><input type="button" value="刪除"></a></div>');      x++; //text box increment    }return false;});$("body").on("click",".removeclass", function(e){ //user click on remove text    if( x > 1 ) {        $(this).parent('div').remove(); //remove text box        x--; //decrement textbox    }return false;})});</script></body></html>

運行效果圖如下:

以上就是錯新技術頻道小編介紹的關于jQuery實現動態添加、刪除按鈕及input輸入框的方法,該介紹完成之后,就能進入項目體現效果,享受編程的樂趣了。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 泗阳县| 铁岭市| 鹤山市| 温州市| 张掖市| 象州县| 上虞市| 灵寿县| 香格里拉县| 阿尔山市| 托克逊县| 桦川县| 兴文县| 汉源县| 新田县| 乐安县| 三穗县| 龙口市| 阿勒泰市| 大石桥市| 当雄县| 福贡县| 博野县| 莱州市| 恩施市| 民勤县| 皮山县| 长泰县| 尚义县| 综艺| 法库县| 昌图县| 丰原市| 宁明县| 庐江县| 宁蒗| 吐鲁番市| 嘉黎县| 宾川县| 河津市| 仁布县|