新增和修改作业增加js验证

This commit is contained in:
sw 2014-11-04 16:27:34 +08:00
parent 13c362b08d
commit d520f1cdb4
2 changed files with 40 additions and 6 deletions

View File

@ -14,7 +14,24 @@
} }
function submit_homework_form() function submit_homework_form()
{ {
$('#edit_homework_attach_<%= @homework.id%>').submit(); if(regexName()){$('#edit_homework_attach_<%= @homework.id%>').submit();}
}
function regexName()
{
var name = $("#homework_attach_name").val();
if(name=="")
{
$("#homework_attach_name_span").text("名称不能为空");
$("#homework_attach_name_span").css('color','#ff0000');
return false;
}
else
{
$("#homework_attach_name_span").text("填写正确");
$("#homework_attach_name_span").css('color','#008000');
return true;
}
} }
</script> </script>
</head> </head>
@ -44,7 +61,8 @@
<%= form_for(@homework) do |f|%> <%= form_for(@homework) do |f|%>
<p> <p>
<label><span class="c_red">*</span>&nbsp;&nbsp;作品名称&nbsp;&nbsp;&nbsp;&nbsp;</label> <label><span class="c_red">*</span>&nbsp;&nbsp;作品名称&nbsp;&nbsp;&nbsp;&nbsp;</label>
<%= f.text_field :name, :required => true, :name => "homework_name", :class => "w430 bo", :maxlength => 254, :placeholder => "作品名称"%> <%= f.text_field :name, :required => true, :name => "homework_name", :class => "w430 bo", :maxlength => 254, :placeholder => "作品名称", :onblur => "regexName();"%>
<span id="homework_attach_name_span"></span>
</p> </p>
<p> <p>
<label>&nbsp;&nbsp;&nbsp;提交项目 <label>&nbsp;&nbsp;&nbsp;提交项目

View File

@ -1,9 +1,24 @@
<%= stylesheet_link_tag 'css', :media => 'all' %> <%= stylesheet_link_tag 'css', :media => 'all' %>
<script type="text/javascript" language="javascript"> <script type="text/javascript" language="javascript" xmlns="http://www.w3.org/1999/html">
function submit_homework_form() function regexName()
{ {
$('#new_homework_attach').submit(); var name = $("#homework_attach_name").val();
if(name=="")
{
$("#homework_attach_name_span").text("名称不能为空");
$("#homework_attach_name_span").css('color','#ff0000');
return false;
} }
else
{
$("#homework_attach_name_span").text("填写正确");
$("#homework_attach_name_span").css('color','#008000');
return true;
}
}
function submit_homework_form(){if(regexName()){$('#new_homework_attach').submit();}}
</script> </script>
<div class="container"> <div class="container">
<div class="Newwork"> <div class="Newwork">
@ -36,7 +51,8 @@
</span> </span>
&nbsp;&nbsp;作品名称&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;作品名称&nbsp;&nbsp;&nbsp;&nbsp;
</label> </label>
<%= f.text_field "name", :required => true, :size => 60, :class => "w430 bo", :maxlength => 254, :placeholder => "作品名称" %> <%= f.text_field "name", :required => true, :size => 60, :class => "w430 bo", :maxlength => 254, :placeholder => "作品名称", :onblur => "regexName();" %>
<span id="homework_attach_name_span"></span>
</p> </p>
<p> <p>
<label>&nbsp;&nbsp;&nbsp;提交项目 <label>&nbsp;&nbsp;&nbsp;提交项目