删除jquery中的文本字段值
Remove text field value in jquery
当我点击add时,它会显示带有值的文本字段。当我点击删除它的隐藏。但当我点击删除时,我也想删除文本字段值。
Css
#second {
display: none;
}
#third {
display: none;
}
#forth {
display: none;
}
#fifth {
display: none;
}
html
<div id="header">
<a href="#" id="add1">add</a> - <a href="#" id="remove">remove</a>
<div id="first" class="toggle"><input type="text" value="1" name="sid[]">first</div>
<div id="second" class="toggle"><input type="text" value="2" name="sid[]">second</div>
<div id="third" class="toggle"><input type="text" value="3" name="sid[]">third</div>
<div id="forth" class="toggle"><input type="text" value="4" name="sid[]">forth</div>
<div id="fifth" class="toggle"><input type="text" value="5" name="sid[]">fifth</div>
</div>
Jquery
$(document).ready(function() {
$("#add1").click(function() {
$('.toggle:not(:visible)').first().show();
});
$("#remove").click(function() {
$('.toggle:visible').last().hide();
});
});
这是我的代码:Jsfidle
只需在.hide();
之后添加.find('input').val('');
即可成为
$('.toggle:visible').last().hide().find('input').val('');
DEMO
尝试以下代码:-
<script>
$(document).ready(function() {
$("#add1").click(function() {
$('.toggle:not(:visible)').first().show();
});
$("#remove").click(function() {
$('.toggle:visible').last().find(':input').val('');
$('.toggle:visible').last().hide();
});
});
</script>
使用此
$(document).ready(function() {
$("#add1").click(function() {
$('.toggle:not(:visible)').first().show();
});
$("#remove").click(function() {
$('.toggle:visible').last().hide().find('input').val('');
});
});
Jsfaddel
hi现在使用到.find()和.val()就像这个一样
$(document).ready(function() {
$("#add1").click(function() {
$('.toggle:not(:visible)').first().show();
});
$("#remove").click(function() {
var valNon = $('.toggle:visible').last().hide();
valNon.find('input').val(''); // add this line
});
});
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 当设置addFromAutocompleteOnly时,剩余文本将保留在输入字段中
- 使用jquery将输入字段转换为文本
- 如何从查询字符串中的输入字段发回文本
- 表单输入字段随着溢出的文本而增长
- 使用单个文本框向多个字段添加严格搜索
- 使用javascript提交表单并从字段/单选框/复选框/文本区域获取数据
- 使用jQuery的输入字段文本换行
- 向使用jQuery加载DOM后添加的字段添加不受限制的文本输入DatePickers
- 当用户单击按钮(在光标位置)时,在输入字段中添加一个文本字符串
- 如何根据文本长度立即显示和隐藏字段?-JQuery
- 当输入字段(文本框)有值时,选中/取消选中复选框
- 重置时输入字段文本css
- 将输入字段文本放入变量中并将其用于 jquery JSON get 请求
- 在 html 输入字段 (文本框) 中插入 javascript (jquery) 变量
- 搜索字段文本没有't在FF 3.6中显示
- 主干集合url操作与输入字段文本
- 如何大写输入字段文本的第一个字母,而键入javascript
- 如何使用angularjs在同一字段中键入时动态格式化输入字段文本
- 如何将输入字段(文本框)添加到使用jQuery动态创建的表中