|
|
|
| Есть функция function keyb_change() создающая область ввода
которая вводит принажатии на ней кнопочек символы в поле определенном с id = textfield
text = document.getElementById("textfield");
как мне переписать document.getElementById("textfield") чтобы оно вводило в то поле ввода, которое сейчас активно?
спасибо! | |
|
|
|
|
|
|
|
для: smust
(05.12.2009 в 20:27)
| | 1. Введите вне функций глобальную переменную, например, IdFocus и дайте ей начальное значение -
var IdFocus = 'textfield';
|
2. На каждое текстовое поле "повесьте" следующий код на событие получения фокуса -
<input id="какой-то_уникальный_идентификатор" onfocus="IdFocus = this.id">
и
<textarea id="другой_уникальный_идентификатор" onfocus="IdFocus = this.id"></textarea>
...и, наконец,
<textarea id="textfield" onfocus="IdFocus = this.id"></textarea>
|
3. Внутри функции keyb_change() определяйте переменную text1 следующим образом -
var text1 = document.getElementById (IdFocus);
|
------
* "Нормальные пацаны" переменной имя существующего атрибута (свойства, объекта, метода) не дают - это плохой тон.
Потому именно text1, а не text. | |
|
|
|
|
|
|
|
для: АЯ
(05.12.2009 в 23:12)
| | Сделал, вот
заменил везде text на text1
единственное text1 = document.getElementById(IdFocus); без var написал (с ним тоже пробовал) так как она снаружи определилась
вот весь текст вызова
var opened = false, vkb = null, text1 = null;
var IdFocus = 'textfield';
function keyb_change()
{
var text1 = document.getElementById(IdFocus);
document.getElementById("switch").innerHTML = (opened ? "Показать клавиатуру" : "Скрыть клавиатуру");
opened = !opened;
if(opened && !vkb)
{
// Note: all parameters, starting with 3rd, in the following
// expression are equal to the default parameters for the
// VKeyboard object. The only exception is 15th parameter
// (flash switch), which is false by default.
vkb = new VKeyboard("keyboard", // container's id
keyb_callback, // reference to the callback function
true, // create the arrow keys or not? (this and the following params are optional)
true, // create up and down arrow keys?
false, // reserved
true, // create the numpad or not?
"", // font name ("" == system default)
"14px", // font size in px
"#000", // font color
"#F00", // font color for the dead keys
"#FFF", // keyboard base background color
"#FFF", // keys' background color
"#DDD", // background color of switched/selected item
"#777", // border color
"#CCC", // border/font color of "inactive" key (key with no value/disabled)
"#FFF", // background color of "inactive" key (key with no value/disabled)
"#F77", // border color of the language selector's cell
true, // show key flash on click? (false by default)
"#CC3300", // font color during flash
"#FF9966", // key background color during flash
"#CC3300", // key border color during flash
false, // embed VKeyboard into the page?
true, // use 1-pixel gap between the keys?
0); // index(0-based) of the initial layout
}
else
vkb.Show(opened);
// text1 = document.getElementById("textfield");
// text1 = document.getElementById(IdFocus);
text1.focus();
if(document.attachEvent)
text1.attachEvent("onblur", backFocus);
}
function backFocus()
{
if(opened)
{
var l = text1.value.length;
setRange(text1, l, l);
text1.focus();
}
}
// Callback function:
function keyb_callback(ch)
{
var val = text.value;
switch(ch)
{
case "BackSpace":
var min = (val.charCodeAt(val.length - 1) == 10) ? 2 : 1;
text1.value = val.substr(0, val.length - min);
break;
case "Enter":
text1.value += "\n";
break;
default:
text1.value += ch;
}
}
function setRange(ctrl, start, end)
{
if(ctrl.setSelectionRange) // Standard way (Mozilla, Opera, ...)
{
ctrl.setSelectionRange(start, end);
}
else // MS IE
{
var range;
try
{
range = ctrl.createTextRange();
}
catch(e)
{
try
{
range = document.body.createTextRange();
range.moveToElementText(ctrl);
}
catch(e)
{
range = null;
}
}
if(!range) return;
range.collapse(true);
range.moveStart("character", start);
range.moveEnd("character", end - start);
range.select();
}
}
//--></SCRIPT></HEAD>
<BODY>
<TABLE border="0" width="60%">
<TR>
<TD width="100px"><TEXTAREA id="textfield" rows="12" cols="50" onfocus="IdFocus = this.id"></TEXTAREA></TD>
<TD width="100px"><TEXTAREA id="textfield1" rows="12" cols="50" onfocus="IdFocus = this.id"></TEXTAREA></TD>
<TD width="100px"><TEXTAREA id="textfield2" rows="12" cols="50" onfocus="IdFocus = this.id"></TEXTAREA></TD>
</TR>
</TABLE>
<P><A href="javascript:keyb_change()" onclick="javascript:blur()" id="switch" style="font-family:Tahoma;font-size:14px;text-decoration:none;border-bottom: 1px dashed #0000F0;color:#0000F0">Виртуальная клавиатура</A></P>
<DIV id="keyboard"></DIV>
</BODY></HTML>
|
не работает...
похоже onfocus="IdFocus = this.id" не срабатывает | |
|
|
|
|
|
|
|
для: smust
(06.12.2009 в 21:54)
| | Неужели никто не знает? | |
|
|
|
|
|
|
|
для: smust
(06.12.2009 в 21:54)
| | >"похоже onfocus="IdFocus = this.id" не срабатывает"
Нет, не так.
onfocus прекрасно срабатывает, что вы легко могли бы проверить и сами:
onfocus="IdFocus = this.id; alert (IdFocus)"
|
Похоже, что у вас не срабатывает в другом месте.
Не буду уточнять - в каком именно месте... чтобы вас не обидеть.
ГДЕ у вас определён метод Show (), который вы пытаетесь вызвать?
Если только - "в ваших мечтах"... | |
|
|
|
|
|
|
|
для: АЯ
(11.12.2009 в 00:56)
| | Лихо было бы обижаться прося помощи :-)
Метод Show в другом скрипте, я не приводил весь код.
А проблему я решил передавая в этот самый show id как переменную.
Не очень изящно и универсально, но проблему решило
Спасибо за помощь! | |
|
|
|