<form onsubmit="return check()" name="add_data">
<input type="text" name="user_name" >
<button type="submit"> 提交 </button>
</form>
function check(){
if (document.forms["add_data"]["user_name"].value == "") {
document.forms["add_data"]["user_name"].classList.add('focus:border-red-500');
document.forms["add_data"]["user_name"].focus();
alert('「用來名稱」未填');
return false;
}
}