z作业留言的字数控制

This commit is contained in:
z9hang 2014-11-12 17:02:35 +08:00
parent e6aa9d3592
commit 227a7c1f31
2 changed files with 40 additions and 2 deletions

View File

@ -69,7 +69,9 @@
<% if User.current.logged? %>
<%= f.text_area 'user_message', :rows => 3, :cols => 65,
:style => "resize: none;", :class => 'noline', :placeholder => l(:text_caracters_maximum,:count=>250)%>
:style => "resize: none;", :class => 'noline', :placeholder => l(:text_caracters_maximum,:count=>250),
:maxlength => 250
%>
<%= f.text_field :reference_user_id, :style=>"display:none"%>
<div style="float:right">
<a href="#" class="ping_sub1" id="jours_submit" onclick="submit1();"><%= l(:label_submit_comments) %></a>

View File

@ -1,6 +1,42 @@
<% reply_allow = JournalsForMessage.create_by_user? User.current %>
<script type="text/javascript" language="javascript">
var W3CDOM = document.createElement && document.getElementsByTagName;
// window.onload = setMaxLength;
$(document).ready(setMaxLength());
function setMaxLength() {
if (!W3CDOM) return;
var textareas = document.getElementsByTagName('textarea');
for (var i=0;i<textareas.length;i++) {
var textarea = textareas[i];
setMaxLengthItem(textareas[i]);
}
}
function setMaxLengthItem(textarea){
if (textarea.getAttribute('maxlength')) {
var counter = document.createElement('div');
counter.className = 'counter';
var counterClone = counter.cloneNode(true);
counterClone.innerHTML = '<span>0</span>/'+textarea.getAttribute('maxlength');
textarea.parentNode.insertBefore(counterClone,textarea.nextSibling);
textarea.relatedElement = counterClone.getElementsByTagName('span')[0];
textarea.onkeyup = textarea.onchange = checkMaxLength;
textarea.onkeyup();
}
}
function checkMaxLength() {
var maxLength = this.getAttribute('maxlength');
var currentLength = this.value.length;
if (currentLength > maxLength)
this.relatedElement.className = 'toomuch';
else
this.relatedElement.className = '';
this.relatedElement.firstChild.nodeValue = currentLength;
}
function test(){alert('test');}
//<!CDATA[
function g(o){return document.getElementById(o);}
function HoverLi(n){
@ -74,4 +110,4 @@
<%= render :partial => 'histoey_new' %>
</div>
</div>
</div>