如何在警报内显示列表中所选项目的名称 window
How to display name of a choosen item from a list inside an alert window
每次用户从列表中选择月份时,我都会尝试显示月份的名称。
我设法显示警报,但我想知道如何显示所选或所选月份的名称。
我的意思是,当用户选择月份时,应该会出现以下文本作为示例
month choosen is April
请告诉我如何实现它
app.component.html:
<div> Months :
<select (change) = "changemonths($event)">
<option *ngFor="let i of months">{{i}}</option>
</select>
</div>
app.component.ts:
months = ["Jan", "Feb", "Mar", "April", "May", "Jun",
"July", "Aug", "Sept", "Oct", "Nov", "Dec"];
changemonths(event) {
alert("Changed month from the Dropdown" + event.value);
console.log(event);
}
alert("更改月份" + event.target.value);
使用event.target.value
代替event.value
changemonths(event) {
alert("Changed month from the Dropdown" + event.target.value);
console.log(event);
}
演示:https://stackblitz.com/edit/angular-ivy-hzdewq?file=src/app/app.component.ts
每次用户从列表中选择月份时,我都会尝试显示月份的名称。 我设法显示警报,但我想知道如何显示所选或所选月份的名称。 我的意思是,当用户选择月份时,应该会出现以下文本作为示例
month choosen is April
请告诉我如何实现它
app.component.html:
<div> Months :
<select (change) = "changemonths($event)">
<option *ngFor="let i of months">{{i}}</option>
</select>
</div>
app.component.ts:
months = ["Jan", "Feb", "Mar", "April", "May", "Jun",
"July", "Aug", "Sept", "Oct", "Nov", "Dec"];
changemonths(event) {
alert("Changed month from the Dropdown" + event.value);
console.log(event);
}
alert("更改月份" + event.target.value);
使用event.target.value
代替event.value
changemonths(event) {
alert("Changed month from the Dropdown" + event.target.value);
console.log(event);
}
演示:https://stackblitz.com/edit/angular-ivy-hzdewq?file=src/app/app.component.ts