【前端】表单事件添加

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011240016/article/details/84136769

HTML:

<form id="myForm">
	<div class="form-group">
		<label>Site Name</label>
		<input type="text" class="form-control" id="siteName" placeholder="Website Name">
	</div>
	<div class="form-group">
		<label>Site URL</label>
		<input type="text" class="form-control" id="siteUrl" placeholder="Website URL">
	</div>
	<button type="submit" class="btn btn-primary">Submit</button>
</form>

JS:

// 为表单添加监听事件
document.getElementById('myForm').addEventListener('submit', saveBookmark);

function saveBookmark() {
	//...
}

这里也就是刻意强调一下addEventListener的用法。

END.

猜你喜欢

转载自blog.csdn.net/u011240016/article/details/84136769