手机版

jquery动态增加文本元素以及删除文本内容实例代码

时间:2021-11-18 来源:互联网 编辑:宝哥软件园 浏览:

这段代码是通过jquery动态增加限定数额的文本(本例为5个) ,以及清除文本内容,用到了之后()方法追加元素。-以下为脚本代码开始-复制代码代码如下:脚本$(文档)。ready(function(){ var spot max=5;//限定添加文本元素的总个数id=0后的var//要追加元素的id var新id=1;//新生成文本的id if($(“表#投票”).size()=spot max){ } $(' # btnAddOption ').单击(id后的function(){ 0;id 1之后的新id=1;addSpot(这个,spotMax,afterId,新id);});});//添加选项方法函数addSpot(obj,sm,afterId,newId) { if($('tr.spot ').size()sm){ $(“id”后的“# vote _”).after(' tr id=' vote _ ' newId ' ' class=' spot ' th ' after id '/th ' t input type=' text ' id=' txtInput _ ' after id ' ' class=' input-text ' value=' size=' 40 ' name=' names '/TD ' '/tr ');$(':text[id^='txtInput_']')." val("输入文本.');//给新增的文本赋予初始值} else{ alert('最多只能添加5项投票!');} };//重置选项$(“输入#btnResetOption”).点击(函数(){ $(':text[id^='txtInput_']').val(" ");//清空文本内容});/脚本!-以下为脚本代码结束- !-以下为超文本标记语言代码块开始-复制代码代码如下:表格方法=' post ' id=' updateForm ' action=' admin/vote/doVote '表格单元格填充=0单元格间距=0宽度=' 100% ' class=' table _ form ' tr th width=' 140 '投票名称/th td输入类型=' text ' id=' txt name ' name=' name ' class=' input-text ' value=' size=' 85 '/TD/tr th宽度='140 '投票描述/th TD文本区域id=' TxTDescribe ' class=' input-text ' name='备注cols=' 85 '/文本区域/TD/tr th宽度=' 140 '开始时间/th td输入类型=' text ' id=' dateMin ' class=' input-text ' value=' name=' startDate ' size=' 40 ' readonly=' readonly '/TD/tr tr th width=' 140 '结束时间/th td输入类型=' text ' id=' date max ' class=' input-text ' name=' end date ' size=' 40 ' readonly=' readonly '//TD/tr/tr th宽度='140 '是否多选/th td输入类型=' radio ' id=' TxTendTime ' name=' IsSelect ' value=' 0 ' size=' 40 '/单选输入类型=' radio ' id=' TxTendTime ' name=' IsSelect ' value=' 1 ' size=' 40 '/多选/TD/tr/tr id=' vote _ 1 '第一个宽度='140 '投票选项/th td输入类型=' button ' id=' btnAddOption ' name=' btnAddOption ' class=' button ' value='添加选项/输入类型=' reset ' id=' btnresetopion ' name=' btnresetopion ' class=' button ' value='重置选项//TD/tr/tr id=' save ' th/th TD align=' left '输入类型=' submit ' id=' BTS save ' name=' BTS save ' class=' button ' style=' width :50 px ' value='保存/input type=' submit ' id=' btnClose ' name=' btnClose ' class=' button ' style=' width :50 px ' value='取消//td /tr /table /form! -以下为超文本标记语言代码块开始-以下是运行效果

版权声明:jquery动态增加文本元素以及删除文本内容实例代码是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。