万一长度过大,阻止提交

This commit is contained in:
lizanle 2015-09-25 16:11:12 +08:00
parent c8cbab2d50
commit 959d3f1a93
1 changed files with 17 additions and 6 deletions

View File

@ -1,11 +1,16 @@
<%= javascript_include_tag 'new_user'%>
<script>
$(function(){
limitStrsize('memo_subject',50);
limitStrsize('memo_content',5000);
});
function check_and_submit(){
if($("textarea[name='memo[subject]']").val().trim() != "" && $("textarea[name='memo[content]']").val().trim() != "" ){
if($("textarea[name='memo[subject]']").val().trim().length > 50 ){
$("#error").html('主题不能超过50个字符').show();
return;
}
if($("textarea[name='memo[content]']").val().trim().length > 5000 ){
$("#error").html('内容不能超过5000个字符').show();
return;
}
$("#edit_memo").submit();
}else if($("textarea[name='memo[subject]']").val().trim() == "" && $("textarea[name='memo[content]']").val().trim() != "" ){
$("#error").html("主题不能为空").show();
@ -19,7 +24,7 @@
</div>
<div class="postRightContainer" style="margin-top: 15px">
<%= labelled_form_for(@memo, :url => forum_memo_path(@memo.forum_id, @memo),:html=>{:id=>'edit_memo'}) do |f| %>
<div id="error" style="display: none">
<div id="error" style="color:red ;display: none">
</div>
<div>
@ -44,4 +49,10 @@
<div class="cl"></div>
</div>
<% end %>
</div>
</div>
<script>
$(function(){
limitStrsize('memo_subject',50);
limitStrsize('memo_content',5000);
});
</script>