如下代码中,页面里有添加和删除按钮,每次点击添加按钮,就会生成一个text框,但点击多次添加按钮之后,生成的几个text把整个页面都占据,这样的话添加和删除按钮就会在最下面,但如果想修改上面生成的text里的内容,然后想继续添加的话,又要用鼠标下拉到窗口的最下面去找添加和删除按钮。所以我想用jquery的方法来实现,添加和删除按钮跟着滚动条的滚动,位置会随之更改,以便用户能在页面的任何位置都能看到添加和删除按钮,貌似有个animate方法,但不会用。html代码
<fieldset>
<legend>New info</legend>
<div><b>调查期间</b>
<input type="text" name="sdate" class="start_date" style="width:100px;" value="" id="dateinput" readonly="readonly"> ~
<input type="text" name="edate" class="end_date" style="width:100px;" value="" id="datepicker" readonly="readonly">
</div>
<table class="formTable" style="display:none;">
<tbody>
<tr>
<th><input type="checkbox" name="title_idx[]" value="">{=_('标题')}</th>
<td colspan="3" class="length"><input class="smalltitles" type="text" name="" value="" ></td>
</tr>
<tr>
<th>{=_('内容')}</th>
<td colspan="3">
<input type="radio" id="textarea" name="select[]" value="textarea"> Textarea
<input type="radio" id="radio" name="select[]" value="radio"> radio button
<input type="radio" id="checkbox" name="select[]" value="checkbox"> checkbox
<br>
<div class="area_child"></div>
</td>
</tr>
</tbody>
</table>
<br>
</fieldset>
<div class="edit">
<button class="btn" id="add">继续</button>
<button class="btn" id="del">删除</button>
</div>JS 代码$('#add').click(function(){
var area = $('.formTable:hidden');
$('fieldset').append('<table class="formTable">'+$(area).html()+'</table>');
reset_textarea($('.formTable:last'));
reset_radio($('.formTable:last'));
reset_checkbox($('.formTable:last'));
}); $('#del').click(function(){
if($('.formTable tbody tr').find('input[type=checkbox]:checked').length < 1)
{
alert('请选择要删除的标题');return;
}
else
{
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().remove();
}
});
<fieldset>
<legend>New info</legend>
<div><b>调查期间</b>
<input type="text" name="sdate" class="start_date" style="width:100px;" value="" id="dateinput" readonly="readonly"> ~
<input type="text" name="edate" class="end_date" style="width:100px;" value="" id="datepicker" readonly="readonly">
</div>
<table class="formTable" style="display:none;">
<tbody>
<tr>
<th><input type="checkbox" name="title_idx[]" value="">{=_('标题')}</th>
<td colspan="3" class="length"><input class="smalltitles" type="text" name="" value="" ></td>
</tr>
<tr>
<th>{=_('内容')}</th>
<td colspan="3">
<input type="radio" id="textarea" name="select[]" value="textarea"> Textarea
<input type="radio" id="radio" name="select[]" value="radio"> radio button
<input type="radio" id="checkbox" name="select[]" value="checkbox"> checkbox
<br>
<div class="area_child"></div>
</td>
</tr>
</tbody>
</table>
<br>
</fieldset>
<div class="edit">
<button class="btn" id="add">继续</button>
<button class="btn" id="del">删除</button>
</div>JS 代码$('#add').click(function(){
var area = $('.formTable:hidden');
$('fieldset').append('<table class="formTable">'+$(area).html()+'</table>');
reset_textarea($('.formTable:last'));
reset_radio($('.formTable:last'));
reset_checkbox($('.formTable:last'));
}); $('#del').click(function(){
if($('.formTable tbody tr').find('input[type=checkbox]:checked').length < 1)
{
alert('请选择要删除的标题');return;
}
else
{
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().remove();
}
});
解决方案 »
- TypeError: this.dom is undefined 苦恼。。
- 向左滚动的文字特效JS代码在uft-8里面不能连续滚动的原因?
- 高手来看下!应该是很入门的ExtJs的问题
- UltraWebGrid如何前端綁定?
- window.locaton为什么在FF可以跳转,在IE和谷歌就不跳转
- RegisterNamespaces 的使用
- 怎么样返回网页中被选中的文字,请大家进来一下
- 请问在javascript中如何执行sqlserver的存储过程
- 怎样检索对象的方法?
- webdig.js?z=7 貌似是一个页面计数器么?放ie中显示出天书一样的无序字母
- 在div中直接显示超链接
- jquery的弹出层插件哪种比较好?
<fieldset>
<legend>New info</legend>
<div><b>调查期间</b>
<input type="text" name="sdate" class="start_date" style="width:100px;" value="" id="dateinput" readonly="readonly"> ~
<input type="text" name="edate" class="end_date" style="width:100px;" value="" id="datepicker" readonly="readonly">
</div>
<table class="formTable" style="display:none;">
<tbody>
<tr>
<th><input type="checkbox" name="title_idx[]" value="">{=_('标题')}</th>
<td colspan="3" class="length"><input class="smalltitles" type="text" name="" value="" ></td>
</tr>
<tr>
<th>{=_('内容')}</th>
<td colspan="3">
<input type="radio" id="textarea" name="select[]" value="textarea"> Textarea
<input type="radio" id="radio" name="select[]" value="radio"> radio button
<input type="radio" id="checkbox" name="select[]" value="checkbox"> checkbox
<br>
<div class="area_child"></div>
</td>
</tr>
</tbody>
</table>
<br>
</fieldset>
<div class="edit">
<button class="btn" id="add">继续</button>
<button class="btn" id="del">删除</button>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script>
$('#add').click(function(){
var area = $('.formTable:hidden');
$('fieldset').append('<table class="formTable">'+$(area).html()+'</table>');
$('body').animate({
scrollTop:$('body').height()
})
reset_textarea($('.formTable:last'));
reset_radio($('.formTable:last'));
reset_checkbox($('.formTable:last'));
});$('#del').click(function(){
if($('.formTable tbody tr').find('input[type=checkbox]:checked').length < 1)
{
alert('请选择要删除的标题');return;
}
else
{
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().next().remove();
$('.formTable tbody tr').find('input[type=checkbox]:checked').parent().remove();
}
});
</script>楼主 这个意思?
<span class="bigtitle">Big Title<input id="bigname" type = "text" name="big_name" value=""></span>
<div id="use_flag">
<input type="checkbox" name="use_flag" id="use_flag" value="T" checked>使用与否
</div>
<fieldset>
<legend>New info</legend>
<div><b>调查期间</b>
<input type="text" name="sdate" class="start_date" style="width:100px;" value="" id="dateinput" readonly="readonly"> ~
<input type="text" name="edate" class="end_date" style="width:100px;" value="" id="datepicker" readonly="readonly">
</div>
<table class="formTable" style="display:none;">
<tbody>
<tr>
<th><input type="checkbox" name="title_idx[]" value="">{=_('标题')}</th>
<td colspan="3" class="length"><input class="smalltitles" type="text" name="" value="" ></td>
</tr>
<tr>
<th>{=_('内容')}</th>
<td colspan="3">
<input type="radio" id="textarea" name="select[]" value="textarea"> Textarea
<input type="radio" id="radio" name="select[]" value="radio"> radio button
<input type="radio" id="checkbox" name="select[]" value="checkbox"> checkbox
<br>
<div class="area_child"></div>
</td>
</tr>
</tbody>
</table>
<br>
</fieldset>
<div class="edit">
<button class="btn" id="add">继续</button>
<button class="btn" id="del">删除</button>
</div>
</form>
<button class="btn" id="add">继续</button>
<button class="btn" id="del">删除</button>
</div>