我正在玩angular2。我想改变div的值 需要将所有 contenteditable =" false" 更改为 contenteditable =" true" ,这些都在我的HTML网页上。
请注意有时候contenteditable =" false"将被添加到DIV标签,有时添加到P,h1标签或其他一些标签。
html如下所示:
View contentView = bottomSheetDialog.findViewById(android.R.id.content);
请指导我应该在<button (click)="selectDiv()">select div</button>
<section>
<div class="content">
<h1 contenteditable="false" >Resize your browser and see how they adapt.</h1>
<h1 contenteditable="false" >text2.</h1>
</div>
<div class="content" contenteditable="false">
<p>Content 2.</p>
<h1>text2.</h1>
</div>
</section>
写什么,以便当我点击按钮时,调用explore.ts
并执行该功能,所有 contenteditable =&#34; false&# 34; 变为&#34; true&#34;
请注意,可以有任何数量的contenteditable =&#34; false&#34;在我的代码中。
selectDiv()
答案 0 :(得分:1)
对于Angular方式:
HTML
<button (click)="selectDiv()">select div</button>
<section>
<div class="content">
<h1 [contentEditable]="contentEditable">Resize your browser and see how they adapt.</h1>
<h1 [contentEditable]="contentEditable">text2.</h1>
</div>
<div class="content" [contentEditable]="contentEditable">
<p>Content 2.</p>
<h1>text2.</h1>
</div>
</section>
TypeScript控制器
...
private contentEditable: boolean = false;
...
selectDiv(): void {
this.contentEditable = true;
}
...
答案 1 :(得分:0)
您可以查询该属性并使用attr
属性更新其值。
此处将选择具有h1
属性
contenteditable
function selectDiv() {
$("h1[contenteditable='false']").attr('contenteditable', true)
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="selectDiv()">
select div</button>
<section>
<div class="content">
<h1 contenteditable="false">Resize your browser and see how they adapt.</h1>
<h1 contenteditable="false">text2.</h1>
</div>
<div class="content" contenteditable="false">
<p>Content 2.</p>
<h1>text2.</h1>
</div>
</section>
&#13;