如何在文本框中生成用户给定值的索引
How to generate Index of user given value in textbox?
如何设置索引到用户给定的值在文本框及其附加到下表在新创建的行,但如何显示索引在每一行第一列在我的表?我是第一次使用这种功能。
$(document).ready(function(){
$('#addbtn').click(function(){
var s = $.trim($('#user').val());
var i = 0;
var c = 1;
var count = i+c;
if(s !=''){
$('#result').attr('src','http://www.clipartbest.com/cliparts/abT/y4b/abTy4bcL7.png');
$('#usertbl').append('<tr height='"30'">'+'<td>'+count+'</td>'+'<td>'+s+'</td>'+'<td>'+'</td>'+'</tr>');
}
$('#user').val(' ');
});
});
table,tr,th,td{
border:1px solid #dddddd;
border-collapse:collapse;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="user"/>
<button id="addbtn">Add</button><span><img src="http://pix.iemoji.com/images/emoji/apple/ios-9/256/cross-mark.png" id="result" height="50" width="50"/></span>
<table style="width:100%;" id="usertbl">
<tr height="30">
<th width="34%">Serial Number</th>
<th width="33%">User NAme</th>
<th width="33%">Content</th>
</tr>
</table>
$(document).ready(function(){
var count = 1;
$('#addbtn').click(function(){
var s = $.trim($('#user').val());
if(s !=''){
$('#result').attr('src','http://www.clipartbest.com/cliparts/abT/y4b/abTy4bcL7.png');
$('#usertbl').append('<tr height='"30'">'+'<td>'+count+'</td>'+'<td>'+s+'</td>'+'<td>'+'</td>'+'</tr>');
count++;
}
$('#user').val(' ');
});
$('#user').keyup(function(){
$('#result').attr('src','http://pix.iemoji.com/images/emoji/apple/ios-9/256/cross-mark.png');
});
});
table,tr,th,td{
border:1px solid #dddddd;
border-collapse:collapse;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="user"/>
<button id="addbtn">Add</button><span><img src="http://pix.iemoji.com/images/emoji/apple/ios-9/256/cross-mark.png" id="result" height="50" width="50"/></span>
<table style="width:100%;" id="usertbl">
<tr height="30">
<th width="34%">Serial Number</th>
<th width="33%">User NAme</th>
<th width="33%">Content</th>
</tr>
</table>
在单击事件之外声明变量,并在单击时使用增量覆盖它。
声明I上面的点击功能。
ie - i = 0;
您可以计算行数并将其用于索引
var $tbl = $('#usertbl');
var count = $('tr', $tbl).length;
示例:https://jsfiddle.net/wbhuccd7/
相关文章:
- 名称输入的索引
- 在jQuery中获取表的行索引
- 测试索引值是否等于某个数字的倍数
- 循环遍历数组中的特定索引
- 按照选项卡索引的顺序循环一个jQuery选择
- 从远程脚本获取用户IP
- 如何调用索引/索引路由'用户后的s模型挂钩's的授权
- 将用户输入分配给索引中带有变量的对象
- 在React中,我如何将用户重定向回状态已更改的索引
- 用户:索引未定义
- 在用户更改选项卡索引时从外部文件调用JS函数
- 如何在数组中得到这个用户的实际索引
- 如何在文本框中生成用户给定值的索引
- 根据用户组重定向到着陆页或主页索引
- 如何用用户需求替换索引值
- 如何让javascript显示用户鼠标点击的表的索引
- 索引数据库用户权限
- 用户关闭一个选项卡(意味着注销)的许多选项卡,这些都没有重定向到索引
- 我有一个IE通知页面,但我怎么能让用户跳过它,并转发回索引
- 在Ajax中,按钮不会在用户索引页面上更新