Increase id with 1
Increase id with 1
>我想要以下内容:当用户单击按钮时,ID 必须增加 1。现在,我使用熟悉的函数为我的行提供唯一 id,并且可以正常工作。现在,我已经对唯一的输入字段使用了相同的代码片段,但这不起作用。同样奇怪的是,以下代码在 name 属性上正确完成了他的工作。
clone.find('#dsmeta_image_caption').prop('name', 'dsmeta_image_caption[' + row.length + ']'); // we now need to set the new ID for the row - ID's cannot be duplicated. This again will use the row.length
所以我想要的是用 1 增加每个字段 id。
代码 JS:
function create_row_event(event) {
// Declared variable
var row = jQuery('tbody tr.row');
var clone = row.last().clone(true);
// Find the cloned fields and reset the values of it
clone.find('input[type=text], text, textarea, select, input.upload_image').val(''); // Reset the values
clone.find('.preview_image').attr('src', ''); // Reset the values
row.parent('tbody.ui-sortable').append(clone); // Append the new row to the body
clone.prop('id', 'repeatable-[' + row.length + ']'); // we now need to set the new ID for the row - ID's cannot be duplicated. This again will use the row.length
clone.find('input#dsmeta_image_caption').prop('id', '[' + row.length + ']');
}
在这里你可以看到代码:http://jsfiddle.net/Caspert/ttgMc/7/
find('#id')
操作将不起作用,因为那里涉及重复的 ID。一旦文档中存在重复的 ID,您就不能指望基于 ID 的选择器/过滤器正常工作。
使用例如 相反find('input:text')
,它会起作用。
相关文章:
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- difference between '$(<%= DDL.ID %>) & $('
- Fighting with FRP
- Error with this.id in Javascript
- Dissect an id with javascript?
- Nested Views with Dynamic Id's Angular & Rails
- CallAjax with ID
- JavaScript createElement with ID
- JQuery appendTo Div with ID instead of appendTo('body
- Change DIV id with javascript
- 如何收集整个
inner html with id="tripDate"在数组中,并使用当前日 - jQuery .find() with an iD
- Rails fields_for enumerate with id
- select with $('#id ul li') & excluding .class
- Choose ID With Contextmenu
- JQuery with Element ID
- Jquery AJAX id选择器和post with change类
- Increase id with 1
- GET id from php with javascript
- Jquery检查li with id=x是否已经存在于ul中