我JS的JavaScript不工作的文件警报如果周期
function myFunction() {
var component = (document.getElementById("component").value);
var author = (document.getElementById("author").value);
var version = (document.getElementById("version").value);
var changelog = (document.getElementById("changelog").value);
if (component == "" || author == "" || version == "" || changelog == "") {
alert("Please Fill All Fields");
} else {
alert("submission Completed");
}}
我的HTML文件
<form>
<h2>Insert Component:</h2>
<input id="component" type = "text" placeholder = "New Component">
<h2>Author:</h2>
<input id="author" type = "text" placeholder = "Author Name">
<h2>Version:</h2>
<input id="version" type = "text" placeholder = "New Version">
<h2>Changelog:</h2>
<input id="changelog" type = "text" placeholder = "">
<br>
<br>
<h1><input style="width:100px;height:30px;font-size: 20" name="submit" type = "button" onclick="myFunction()" value="Submit"></h1>
</form>
另外,如果我完成所有的表单字段没有显示的第二警报,总是第一个显示...有人可以帮助我吗?我实在无法理解
你的ID是错的 - ID是区分大小写的。您的html将id显示为小写,但是您将首字母搜索为大写字母 –
仅供参考,您可以省略每个“document.getElementById(”XXX“).value”周围的括号。 – reformed
对不起,我发布了一个旧版本。它不适用于使用小写的ID号 –