|
|
|
| Всем привет. На страничке выполняется пару скриптов:
- скрипт добавления textarea параметр maxlenght;
- скрипт показывающий пользователю сколько ему осталось ввести символов;
- скрипт вырезающий/заменяющий плохие слова;
- скрипт разделяющий длинное слово.
Так вот первые 3 работают без последнего нормально. Как только я добавляю последний, он начинает работать, а три первых перестают.
Первый вариант когда 3 скрипта работает нормально:
<script>
function ismaxlength(obj)
{
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}
</script>
<script>
function check (area)
{
var changer =
{
'блин' : '',
}
for (i in changer)
eval ("area.value = area.value.replace (/"+i+"/gi, '"+changer[i]+"');");
}
</script>
<form class='form' action="comment.php" method="post" name="form_com">
Текст комментария: <br><textarea maxlength="400"
onFocus="this.style.background='#e0f7bd'"
onkeyup="check(this); document.getElementById ('count').value = 400 - this.value.length; if(document.getElementById ('count').value < 100) {count.style.color='#FF3333'} else {count.style.color='#000000'} if(document.getElementById ('count').value < 0) {document.getElementById ('count').value = 0} return ismaxlength(this)"
onBlur="this.style.background='#FFFFFF'" name="text" cols="67" rows="8"></textarea>
Осталось <input readonly="readonly" style="border:0px; font-size:12px; text-align:center" id="count" size="1" value="400"> символа(ов).
</form>
|
Второй вариант добавил скрипт ниже формы и прописал ID в textarea
<script>
function ismaxlength(obj)
{
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}
</script>
<script>
function check (area)
{
var changer =
{
'блин' : '',
}
for (i in changer)
eval ("area.value = area.value.replace (/"+i+"/gi, '"+changer[i]+"');");
}
</script>
<form class='form' action="comment.php" method="post" name="form_com">
Текст комментария: <br><textarea id="textareaId" maxlength="400"
onFocus="this.style.background='#e0f7bd'"
onkeyup="check(this); document.getElementById ('count').value = 400 - this.value.length; if(document.getElementById ('count').value < 100) {count.style.color='#FF3333'} else {count.style.color='#000000'} if(document.getElementById ('count').value < 0) {document.getElementById ('count').value = 0} return ismaxlength(this)"
onBlur="this.style.background='#FFFFFF'" name="text" cols="67" rows="8"></textarea>
Осталось <input readonly="readonly" style="border:0px; font-size:12px; text-align:center" id="count" size="1" value="400"> символа(ов).
</form>
<script>
var _textarea = document.getElementById('textareaId');
_textarea.onkeyup= function () {wraptext();}
function wordwrap( str, int_width, str_break, cut ) {
var m = ((arguments.length >= 2) ? arguments[1] : 75 );
var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
var c = ((arguments.length >= 4) ? arguments[3] : false);
var i, j, l, s, r;
str += '';
if (m < 1) {
return str;
}
for (i = -1, l = (r = str.split("\n")).length; ++i < l; r[i] += s) {
for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
}
}
return r.join("\n");
}
function wraptext () {
var words = _textarea.value.split(" ");
for (var i=0, n=words.length; i<n; i++) {
if (words[i].length > 10) {
words[i] = wordwrap(words[i], 10, " ", true);
}
}
_textarea.value = words.join(" ");
}
</script>
|
Когда ID в textarea убираю 3 скрипта верхнии работают, а последний нет, и наоборот. Помогите оформить так чтобы все скрипты работали не перекрывая друг друга..Буду очень благодарным. | |
|
|