This commit is contained in:
ouyangxuhua 2015-09-25 16:30:22 +08:00
commit 6857b62f00
6 changed files with 28 additions and 15 deletions

View File

@ -9,10 +9,10 @@
<div id="error" style="display: none;color: red;"> <div id="error" style="display: none;color: red;">
</div> </div>
<div> <div>
<textarea type="text" id="forum_name" name="forum[name]" class="postCreateInput" placeholder="对应贴吧名称" ><%= @forum.name.html_safe%></textarea> <textarea type="text" id="forum_name" name="forum[name]" maxlength="50" class="postCreateInput" placeholder="对应贴吧名称" ><%= @forum.name.html_safe%></textarea>
</div> </div>
<div class="mt15"> <div class="mt15">
<textarea type="text" id="forum_desc" name="forum[description]" class="postCreateInput" placeholder="对应贴吧描述" ><%= @forum.description.html_safe%></textarea> <textarea type="text" id="forum_desc" name="forum[description]" maxlength="5000" class="postCreateInput" placeholder="对应贴吧描述" ><%= @forum.description.html_safe%></textarea>
</div> </div>
<div class="mt10"> <div class="mt10">
<div class="fr"><a href="javascript:void(0);" class="submit_btn" onclick="check_and_submit($(this));">确定</a></div> <div class="fr"><a href="javascript:void(0);" class="submit_btn" onclick="check_and_submit($(this));">确定</a></div>

View File

@ -54,7 +54,7 @@
$('#forum_name').keypress(function(e) $('#forum_name').keypress(function(e)
{ {
var n = 0; var n = 0;
var str = this.value; var str = this.val().trim();
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码 var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) { if (leg > 255) {

View File

@ -51,8 +51,9 @@
}); });
$('#forum_name').keypress( function(e) $('#forum_name').keypress( function(e)
{ {
alert(1)
var n = 0; var n = 0;
var str = this.value; var str = this.val().trim();
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码 var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {//大于255的都是中文 if (leg > 255) {//大于255的都是中文
@ -61,6 +62,7 @@
n += 1;//英文,不多说了 n += 1;//英文,不多说了
} }
} }
console.log(n)
if(n >= 160 && e.keyCode != 8) if(n >= 160 && e.keyCode != 8)
if(document.all) if(document.all)
{ {
@ -136,14 +138,14 @@
<div class="red fl mb10" id="error" style="display: none">error</div> <div class="red fl mb10" id="error" style="display: none">error</div>
<%= form_tag({:controller => 'forums',:action=>'create',:format=>'js'},:method => 'post',:remote=>'true') do |f| %> <%= form_tag({:controller => 'forums',:action=>'create',:format=>'js'},:method => 'post',:remote=>'true') do |f| %>
<div class="mt15"> <div class="mt15">
<textarea type="text" name="forum[name]" id="forum_name" class="postCreateInput" onfocus="hideError();" onblur="check_forum_name();" placeholder="输入贴吧名称" ></textarea> <textarea type="text" name="forum[name]" id="forum_name" maxlength="80" class="postCreateInput" onfocus="hideError();" onblur="check_forum_name();" placeholder="输入贴吧名称" ></textarea>
<script> <script>
var textarea = document.getElementById('forum_name'); var textarea = document.getElementById('forum_name');
autoTextarea(textarea); autoTextarea(textarea);
</script> </script>
</div> </div>
<div class="mt15"> <div class="mt15">
<textarea type="text" name="forum[description]" id="forum_desc" class="postCreateInput" placeholder="输入贴吧描述"></textarea> <textarea type="text" name="forum[description]" id="forum_desc" maxlength="5000" class="postCreateInput" placeholder="输入贴吧描述"></textarea>
<script> <script>
var textarea1 = document.getElementById('forum_desc'); var textarea1 = document.getElementById('forum_desc');
autoTextarea(textarea1); autoTextarea(textarea1);

View File

@ -92,14 +92,14 @@
<div id="error" class="red fl mb10" style="display: none">error</div> <div id="error" class="red fl mb10" style="display: none">error</div>
<%= labelled_form_for(@memo, :url => forum_memos_path(@forum)) do |f| %> <%= labelled_form_for(@memo, :url => forum_memos_path(@forum)) do |f| %>
<div> <div>
<textarea type="text" name="memo[subject]" id="memo_subject" onblur="check_memo_name();" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子标题" ></textarea> <textarea type="text" name="memo[subject]" id="memo_subject" maxlength="50" onblur="check_memo_name();" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子标题" ></textarea>
<script> <script>
var textarea1 = document.getElementById('memo_subject'); var textarea1 = document.getElementById('memo_subject');
autoTextarea(textarea1); autoTextarea(textarea1);
</script> </script>
</div> </div>
<div class="mt15"> <div class="mt15">
<textarea type="text" name="memo[content]" id="memo_content" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子内容" /></textarea> <textarea type="text" name="memo[content]" id="memo_content" maxlength="5000" onfocus="$('#error').hide();" onmouseover="this.style.borderColor='#d9d9d9'" class="postDetailInput" placeholder="输入帖子内容" /></textarea>
<script> <script>
var textarea = document.getElementById('memo_content'); var textarea = document.getElementById('memo_content');
autoTextarea(textarea); autoTextarea(textarea);

View File

@ -1,11 +1,16 @@
<%= javascript_include_tag 'new_user'%> <%= javascript_include_tag 'new_user'%>
<script> <script>
$(function(){
limitStrsize('memo_subject',50);
limitStrsize('memo_content',5000);
});
function check_and_submit(){ function check_and_submit(){
if($("textarea[name='memo[subject]']").val().trim() != "" && $("textarea[name='memo[content]']").val().trim() != "" ){ 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(); $("#edit_memo").submit();
}else if($("textarea[name='memo[subject]']").val().trim() == "" && $("textarea[name='memo[content]']").val().trim() != "" ){ }else if($("textarea[name='memo[subject]']").val().trim() == "" && $("textarea[name='memo[content]']").val().trim() != "" ){
$("#error").html("主题不能为空").show(); $("#error").html("主题不能为空").show();
@ -19,7 +24,7 @@
</div> </div>
<div class="postRightContainer" style="margin-top: 15px"> <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| %> <%= 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>
<div> <div>
@ -44,4 +49,10 @@
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<% end %> <% end %>
</div> </div>
<script>
$(function(){
limitStrsize('memo_subject',50);
limitStrsize('memo_content',5000);
});
</script>

View File

@ -340,7 +340,7 @@ function limitStrsize(id,length){
$('#'+id).keypress(function(e) $('#'+id).keypress(function(e)
{ {
var n = 0; var n = 0;
var str = this.value; var str = this.val().trim();
for (i = 0; i < str.length; i++) { for (i = 0; i < str.length; i++) {
var leg = str.charCodeAt(i);//ASCII码 var leg = str.charCodeAt(i);//ASCII码
if (leg > 255) {//大于255的都是中文 if (leg > 255) {//大于255的都是中文