1 //操作元素的属性: 2 $(‘*‘).each(function(n){ 3 this.id = this.tagName + n; 4 }) 5 6 //获取属性值: 7 $(‘‘).attr(‘‘); 8 9 //设置属性值: 10 //为一个属性设置值 11 $(‘*‘).attr(‘title‘, function(index, previousValue){ 12 return previousValue + ‘ I am element ‘ + index + ‘ and my name is ‘ + this.id; 13 }) 14 15 //为多个属性设置值 16 $(‘input‘).attr({value: ‘‘,title: ‘‘}); 17 18 //删除属性: 19 $(‘p‘).removeAttr(‘value‘);
时间: 2024-10-11 04:44:02