Javascript没有'不适用于输入验证
Javascript doesn't work for input validation
我见过很多不同的方法,其中任何一种都适用于我
我正在使用引导程序。
表单直接进入"操作"(我想首先在"onupdate"上验证)
脚本:
[...]
<!-- Bootstrap core CSS -->
<link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="../style.css" rel="stylesheet" type="text/css/">
<script type="text/javascript">
function valForm()
{
alert("HALOOOOOOOOO");
var errors = 0;
var title = document.forms["tutorial_form"]["title"].value;
var description = document.forms["tutorial_form"]["description"].value;
var url = document.forms["tutorial_form"]["url"].value;
if (title == null || title == "")
{
document.getElementById("title_div").style.class = "form-group has-warning";
errors++;
}
if (description == null || description == "")
{
document.getElementById("description_div").style.class = "form-group has-warning";
errors++;
}
if (url == null || url == "")
{
document.getElementById("url_div").style.class = "form-group has-warning";
errors++;
}
if( errors > 0)
{
document.getElementById("error_container").innerHTML = "<div class="alert alert-danger" role="alert"><p><b>ERROR!</b>All the information must be fulfilled.</p></div>";
return false;
}
}
</script>
</head>
形式:
<div class="container">
<form name="tutorial_form" enctype="multipart/form-data" action="insert_tutorial.php" onsubmit="return valForm()" method="post">
<div id="title_div" class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Title input">
</div>
<div id="description_div" class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description" placeholder="Description" rows="5"></textarea>
</div>
<div id="url_div" class="form-group">
<label for="url">Video URL</label>
<input type="text" class="form-control" id="url" name="url" placeholder="Insert youtube url">
</div>
<div class="form-group">
<label for="file">Insert image file</label>
<input type="file" name="image" id="file">
<p class="help-block">Select the file. Take care that it's size is no longer that 16 MB.</p>
</div>
<input type="submit" value="Submit" name="submit" class="btn btn-success">
</form>
<hr>
</div>
提前感谢!!!
如果上一个if语句中出现语法错误,请将双引号改为单引号:
document.getElementById("error_container").innerHTML = "<div class='alert alert-danger' role='alert'><p><b>ERROR!</b>All the information must be fulfilled.</p></div>";
或者你也可以逃离它们:
"<div class='"alert alert-danger'" role='"alert'"><p><b>ERROR!</b>All the information must be fulfilled.</p></div>";
相关文章:
- AddEventListener适用于浏览器,但不适用于Android
- 查找仅适用于原始图像的图像放大算法的名称
- 如何在category.php中执行jquery,这应该适用于类别wordpress中的每个帖子
- Web编程,简单但适用于机器人项目
- JavaScript不适用于internet explorer和Firefox,但适用于谷歌
- Jquery事件处理程序仅适用于匿名函数
- jQuery调整大小函数只适用于窗口
- 火灾在卸载前确认警报仅适用于外部站点
- EmberJS-适用于各种模型的适配器动态名称空间
- Facebook共享链接适用于用户,但不适用于粉丝页面管理员
- jQuery-适用于移动设备的多级菜单
- 循环中的切换脚本只适用于第一次迭代
- 为什么setTimeout适用于无休止的递归调用
- 我未保存的更改指令需要适用于具有不同名称的所有表单
- jQuery表单验证(如果==“执行此操作”)仅适用于第一次输入
- 在backbonejs视图中,keypress/keyup/keydown事件是否仅适用于输入,而不适用于其他元素
- AngularJS 1.3-为什么表单在加载时有效,适用于长度最小的输入
- Jquery - info/docs关于适用于表单中不同类型输入元素的属性列表
- 按钮只适用于点击,而不是输入/返回
- 验证输入的时间只适用于如果我附加了一个断点在chrome调试器