mik*_*rsv 11 html javascript dom angular
event.target返回执行操作的DOM元素.如何从输出中获取特定的子元素?
这是我的表单(使用Angular标记):
<form (ngSubmit)="onSubmit($event)" id="kekpek">
<div class="form-group">
<label>Example file input</label>
<input type="file" class="form-control-file" #fileupload [(ngModel)]="myFile" name="myFile" (change)="fileChange($event)"/>
</div>
<button type="submit" class="btn btn-success">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
它激发了这个功能:
onSubmit(event) {
console.log(event.target);
}
Run Code Online (Sandbox Code Playgroud)
哪个输出整个表格.我需要访问函数中的input元素onSubmit().
Chi*_*dra 14
您可以使用该documentElement.querySelector()方法.
function onSubmit(event){
console.log(event.target.querySelector('input'));
}
Run Code Online (Sandbox Code Playgroud)
您可以使用任何有效的CSS查询来获取所需的元素
| 归档时间: |
|
| 查看次数: |
15317 次 |
| 最近记录: |