角.删除根标签上的属性
Angular. Remove attribute on root tag
我将自己的标签转换为模板:
<div>
<input />
<span></span>
</div>
在我自己的标签中,我只设置了input
的属性。
但是div
也有这些属性。我不能删除它。我尝试使用element.removeAttr('class')
,但它不工作。
<!DOCTYPE html>
<html ng-app="sr">
<head>
<meta charset="utf-8" />
<title>single root tag</title>
<style>
body {background:gray;}
.red {background:red;}
.green {background:green;}
.yellow {background:yellow;}
</style>
<script src="dhtmlxcommon.js"></script>
<script src="dhtmlxcalendar.js"></script>
</head>
<body>
<tag class="{{class}}" width="{{width}}" ></tag><br>
<tag class="{{class}}" width="{{width}}" ></tag><br>
PutIn value for <b>class</b> <input ng-model="class" />red green<br><br>
PutIn value for <b>width</b> <input ng-model="width" />any number
<br>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.1.3/angular.min.js"></script>
<script>
var myapp = angular.module("sr", []);
myapp.directive('tag', function(){
return {
restrict: 'E',
replace: true,
transclude: false,
scope: false,
template:
'<div><input type="text" ng-model="fdg" class="{{class}}" size="{{width}}" ></input><span>text must be here</span></div>'
,
link: function(scope, element, attrs) {
//element.find('input').attr('attr1', '{{value1}}');
//element.find('div').removeAttr('class');
element.removeAttr('class');
element.removeAttr('width');
}
};
});
</script>
</body>
</html>
将class="{{class}}" width="{{width}}"
从<tag>
中移除,如下:http://plnkr.co/edit/f0UidePGJEwp1bep4gUj?p=preview
<tag></tag><br>
<tag></tag><br>
相关文章:
- 查找所有TD标签并读取其数据属性
- 使用json数据更改视频标签中的src属性
- 在jquery中,从同一对象的属性设置输入字段和标签的正确方法是什么
- 至于所有输入的标签都用指定的属性来设置,例如属性检查=false
- 使用 Div 标签的 location.href 属性时,Eval 不起作用
- SEO机器人是否总是遵循A标签的href属性中的URL,即使点击/点击被Javascript拦截
- 如何在 javascript 中为没有值的标签选择属性
- 使用父标签中的样式属性附加新标签
- 如何在 jquery 和 javascript 中检索 html 标签属性
- JavaScript-多次创建具有相同属性的标签
- Wordpress:如何更改图像标签中的源属性
- Wicket:获取标签属性
- 使用jQuery通过更改src属性来设置一个图像标签的动画
- 标签的属性在角度方向上不起作用
- Knockout.js中使用的唯一ID;对于“;单选按钮组中的标签属性
- 如何使用jQuery在属性标签中选择元素ID
- 如何在 struts2 属性标签中给出 javascript 函数和 css 样式
- 创建“title"属性标签
- 访问和更改