Jquery动态添加输入框的方法

<!-- 页头 --> <#include "../common/head.ftl"> <div></div> <div> <form method="post" action="/restaurant/${(user.userId)}/addAddress"> <div> <div><label>地址</label></div> <div> <ul data-role="list"></ul> <div> <input type="text" data-role="item-input"> <span> <button type="button" data-role="item-add" >添加</button> </span> </div> </div> </div> </form> <!-- container --> </div> <script type="text/javascript" src="https://www.jb51.net/${app.basePath}/resources/js/jquery.form.js"></script> <script> $.schoolFn = { addCourseItem: function(obj){ $("#ItemCourseList").append("<li><span></span>"+obj+"<input type='hidden' value='"+obj+"'><button type='button' title='删除'>×</button></li>"); }, addItem: function(obj){ $("#itemList").append("<li><span></span>"+obj+"<input type='hidden' value='"+obj+"'><button type='button' 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"/>

效果图如下:

Jquery动态添加输入框的方法

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgjydd.html