我需要从dom中的元素id中删除一个字符串(" DTE_Field _")。
<select id="DTE_Field_CD_PAIS" dependent-group="PAIS" dependent-group-level="1" class="form-control"></select>
var str=$(el).attr("id");
str.replace("DTE_Field_","");
答案 0 :(得分:0)
使用attr()
method with callback。这将迭代元素,你可以获得旧的属性值作为回调参数,你可以通过使用 String#replace
方法返回 $scope.gridOptions = {
rowHeight:60,
multiSelect: false,
enableColumnMenus:false,
enableEdit: false,
enableSorting: false,
enableFiltering: false,
columnDefs: [
{
field: 'select',
maxWidth: 30,
headerCellTemplate:'<div> <div>',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
cellTemplate: '<div class="inner-data-cell"><input type="checkbox"></div>'
},
{
field: 'status',
minWidth: 75,
maxWidth: 150,
displayName: 'Status',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
'cellTemplate': '<div class="inner-data-cell">{{row.entity.registrationStatus}}</div>'
},
{
field: 'name',
minWidth: 75,
maxWidth: 150,
displayName: 'Name',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
cellTemplate: '<div class="inner-data-cell">{{row.entity.lastName}},{{row.entity.firstName}}</div>'
},
{
field: 'organization',
minWidth: 150,
displayName: 'Org',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
cellTemplate: '<div class="inner-data-cell">{{row.entity.organization}}</div>'
},
{
field: 'registratioDate',
minWidth: 150,
displayName: 'Registration Date',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
cellTemplate: '<div class="inner-data-cell">{{row.entity.registeredOn}}</div>'
},
{
field: 'lastActive',
minWidth: 220,
displayName: 'Last Active',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
cellTemplate: '<div class="inner-data-cell">{{row.entity.lastActive}}</div>'
},
{
field: 'uplaodId',
minWidth: 200,
displayName: 'Upload Id',
headerCellClass: 'grid-header-center',
cellClass: 'grid-data-cell',
cellTemplate: '<div class="inner-data-cell">NA</div>'
}
],
filterOptions: $scope.filterOptions
};
字符串来更新属性。
DTE_FIELD
$('select').attr('id', function(i, oldId) {
return oldId.replace('DTE_field_', '');
});
$('select').attr('id', function(i, oldId) {
return oldId.replace('DTE_Field_', '');
});
如果元素并非总是被选中,那么您可以使用 attribute contains selector
(或如果<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="DTE_Field_CD_PAIS" dependent-group="PAIS" dependent-group-level="1" class="form-control"></select>
始终位于开头,则使用 attribute starts with selector
< /强>)。
DTE_field_
答案 1 :(得分:0)
答案 2 :(得分:0)
像这样使用:
var string=$('#DTE_Field_CD_PAIS').attr("id");
console.log(str.split("DTE_Field_").pop());
答案 3 :(得分:-2)
$('[id^="DTE_FIELD_"]').each(function () {
$(this).attr('id', $(this).attr('id').replace('DTE_FIELD_',''));
});