This commit is contained in:
yanxd 2013-12-28 13:40:22 +08:00
parent 8cb3756bbc
commit 42fa7eb4c1
1 changed files with 0 additions and 36 deletions

View File

@ -1,39 +1,3 @@
<script>
var W3CDOM = document.createElement && document.getElementsByTagName;
window.onload = setMaxLength;
function setMaxLength() {
if (!W3CDOM) return;
var textareas = document.getElementsByTagName('textarea');
var counter = document.createElement('div');
counter.className = 'counter';
for (var i=0;i<textareas.length;i++) {
if (textareas[i].getAttribute('maxlength')) {
var counterClone = counter.cloneNode(true);
counterClone.innerHTML = '<span>0</span>/'+textareas[i].getAttribute('maxlength');
textareas[i].parentNode.insertBefore(counterClone,textareas[i].nextSibling);
textareas[i].relatedElement = counterClone.getElementsByTagName('span')[0];
textareas[i].onkeyup = textareas[i].onchange = checkMaxLength;
textareas[i].onkeyup();
}
}
}
function checkMaxLength() {
var maxLength = this.getAttribute('maxlength');
var currentLength = this.value.length;
alert(currentLength);
if (currentLength >= maxLength) {
this.relatedElement.className = 'toomuch';
}
else {
this.relatedElement.className = '';
}
this.relatedElement.firstChild.nodeValue = currentLength;
}
</script>
<%= form_tag({:controller => 'projects', :action => 'project_respond'}) do %>
<%= text_area_tag 'project_respond', "",
:class => 'noline', :required => true,