Jquery動(dòng)態(tài)添加輸入框的方法
本文實(shí)例講述了Jquery動(dòng)態(tài)添加輸入框的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
<!-- 頁頭 --> <#include "../common/head.ftl"> <div id="onFailureDiv" class="alert alert-danger navbar-fixed-top" style="text-align:center; display:none"></div> <div class="container" style="min-height:100%; height:100%;margin-top:100px;"> <form id="addressForm" class="form-horizontal" method="post" action="/restaurant/${(user.userId)}/addAddress"> <div class="form-group dynamic-collection" id="course-goals-form-group"> <div class="col-md-2 control-label"><label>地址</label></div> <div class="col-md-8 controls"> <ul id="ItemCourseList" class="list-group sortable-list" data-role="list" style="margin-bottom:10px;"></ul> <div class="input-group"> <input id="courseInput" type="text" data-role="item-input" class="form-control"> <span class="input-group-btn"> <button id="addItemCourse" class="btn btn-default" type="button" data-role="item-add" >添加</button> </span> </div> </div> </div> </form> <!-- container --> </div> <script type="text/javascript" src="${app.basePath}/resources/js/jquery.form.js"></script> <script> $.schoolFn = { addCourseItem: function(obj){ $("#ItemCourseList").append("<li class='list-group-item clearfix'><span class='glyphicon glyphicon-resize-vertical sort-handle'></span>"+obj+"<input type='hidden' name='goals' value='"+obj+"'><button type='button' class='close delete-btn deleteItem' onclick='deleteCourseItem(this);' title='刪除'>×</button></li>"); }, addItem: function(obj){ $("#itemList").append("<li class='list-group-item clearfix'><span class='glyphicon glyphicon-resize-vertical sort-handle'></span>"+obj+"<input type='hidden' name='audiences' value='"+obj+"'><button type='button' class='close delete-btn deleteItem' onclick='deleteItem(this);' title='刪除'>×</button></li>"); }, } $("#addItemCourse").click(function(){ var item=$('#courseInput').val(); if(item.trim()==""){ $('#courseInput').val(""); }else{ $.schoolFn.addCourseItem(item); $('#courseInput').val(""); } }); function deleteCourseItem(obj){ $(obj).parent().replaceWith(""); } </script> <script> $(document).ready(function(){ $('#addressForm').ajaxForm(function(json) { if(json.status == "success") { $("#onFailureDiv").html("添加成功").slideDown().delay(3000).hide(1000); }else { $("#onFailureDiv").html(json.errorMsg).slideDown().delay(3000).hide(1000); } }); }); </script> <!-- 頁腳 --> <#include "../common/footer.ftl"/>
效果圖如下:
希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
- jquery實(shí)現(xiàn)input輸入框?qū)崟r(shí)輸入觸發(fā)事件代碼
- js與jquery實(shí)時(shí)監(jiān)聽輸入框值的oninput與onpropertychange方法
- input 輸入框獲得/失去焦點(diǎn)時(shí)隱藏/顯示文字(jquery版)
- jquery清空textarea等輸入框?qū)崿F(xiàn)代碼
- 基于jQuery的input輸入框下拉提示層(自動(dòng)郵箱后綴名)
- jQuery實(shí)現(xiàn)動(dòng)態(tài)添加、刪除按鈕及input輸入框的方法
- jquery實(shí)現(xiàn)textarea輸入框限制字?jǐn)?shù)的方法
- jQuery表單獲取和失去焦點(diǎn)輸入框提示效果的實(shí)例代碼
- 基于jquery實(shí)現(xiàn)一張圖片點(diǎn)擊鼠標(biāo)放大再點(diǎn)縮小
- jQuery div層的放大與縮小簡(jiǎn)單實(shí)現(xiàn)代碼
- jQuery實(shí)現(xiàn)輸入框的放大和縮小功能示例
相關(guān)文章
jQuery實(shí)現(xiàn)仿美橙互聯(lián)兩級(jí)導(dǎo)航菜單的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)仿美橙互聯(lián)兩級(jí)導(dǎo)航菜單的方法,實(shí)例分析了jQuery操作css及setTimeout等實(shí)現(xiàn)導(dǎo)航菜單的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03Laravel admin實(shí)現(xiàn)消息提醒、播放音頻功能
這篇文章主要介紹了Laravel admin實(shí)現(xiàn)消息提醒、播放音頻功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07jQuery移除或禁用html元素點(diǎn)擊事件常用方法小結(jié)
這篇文章主要介紹了jQuery移除或禁用html元素點(diǎn)擊事件常用方法,結(jié)合實(shí)例形式總結(jié)分析了jQuery針對(duì)onclick事件的禁用與屏蔽技巧,需要的朋友可以參考下2017-02-02jquery.uploadify插件在chrome瀏覽器頻繁崩潰解決方法
這篇文章主要介紹了jquery.uploadify插件在chrome瀏覽器頻繁崩潰解決方法,十分的實(shí)用,遇到相同問題,需要解決的朋友可以參考下2015-03-03jQuery控制的不同方向的滑動(dòng)(向左、向右滑動(dòng)等)
這篇文章主要介紹了jQuery控制的不同方向的滑動(dòng)(向左、向右滑動(dòng)等),需要的朋友可以參考下2014-07-07模擬jQuery中的ready方法及實(shí)現(xiàn)按需加載css,js實(shí)例代碼
這篇文章介紹了模擬jQuery中的ready方法及實(shí)現(xiàn)按需加載css,js實(shí)例代碼,有需要的朋友可以參考一下2013-09-09