[英]how to show the hidden text after select a value from select Box?
<div class="column">
<div>
<mat-form-field>
<mat-label>Subject</mat-label>
<mat-select formControlName="Subject">
<mat-option *ngFor="let Subject of Subjects" [value]="Subject.value">
{{Subject.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div>
<mat-form-field>
<mat-label>Grade</mat-label>
<mat-select formControlName="Grade">
<mat-option *ngFor="let Grade of Grades" [value]="Grade.value">
{{Grade.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div>
<mat-form-field>
<mat-label>Type</mat-label>
<mat-select formControlName="Type">
<mat-option *ngFor="let Type of Types" [value]="Type.value">
{{Type.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
//label is here //标签在这里
<div [hidden] = "showLable() === true ? false: true">
<p >Maximum Price exceeding</p>
</div>
export class NewLectureComponent implements OnInit {
isNotify: boolean;
showLable(){
this.isNotify = true;
}
}
You can use the ngIf Directive that can be used to show or hide the html elements when required.您可以在需要时使用ngIf指令来显示或隐藏 html 元素。
<div *ngIf="isNotify">
<p >Maximum Price exceeding</p>
</div>
So when the isNotify value will be true the html element would be added into the doucument if false it would be added as a binding(a template).因此,当 isNotify 值为真时,html 元素将被添加到文档中,如果为假,它将作为绑定(模板)添加。
Please try this code,To how to show the hidden text after select a value from select Box?请尝试此代码,如何显示 select 后的隐藏文本来自 select 框的值?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Elements Using Select Box</title>
<style>
.box{
color: #fff;
padding: 20px;
display: none;
margin-top: 20px;
}
.red{ background: #ff0000; }
.green{ background: #228B22; }
.blue{ background: #0000ff; }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("select").change(function(){
$(this).find("option:selected").each(function(){
var optionValue = $(this).attr("value");
if(optionValue){
$(".box").not("." + optionValue).hide();
$("." + optionValue).show();
} else{
$(".box").hide();
}
});
}).change();
});
</script>
</head>
<body>
<div>
<select>
<option>Choose Color</option>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>
</div>
<div class="red box">You have selected <strong>red option</strong> so i am here</div>
<div class="green box">You have selected <strong>green option</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue option</strong> so i am here</div>
</body>
</html>
I hope this code will be useful.我希望这段代码有用。
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.