Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   Opera, input file, div tabindex (https://javascript.ru/forum/events/29562-opera-input-file-div-tabindex.html)

bes 03.07.2012 17:48

Цитата:

Сообщение от autosoft
Во всех браузерах (кроме Opera) на 6-м шаге инициируется событие onblur первого input.
В Opera - нет. Тестировал на Opera 11 и Opera 12.

Раз нужного эффекта нет, надо искать пути его создания.
Ответ на вопрос "Почему нет?" - "Потому что так сделали!" (в IE тоже много чего есть, чего нет в других браузерах, и наоборот).

devote 03.07.2012 17:51

Цитата:

Сообщение от autosoft
Во всех браузерах (кроме Opera) на 6-м шаге инициируется событие onblur первого input.
В Opera - нет. Тестировал на Opera 11 и Opera 12.

Да вы правы, это Баг в Опере, надо будет репорт отправить.
<script type="text/javascript">
  
function dofocus(self) {document.body.appendChild(document.createTextNode('focus('+self.name+'), '))}
function doblur (self) {document.body.appendChild(document.createTextNode('blur('+self.name+'), '))}
 
</script>
<form id="upload" method="post" enctype="multipart/form-data" action="/upload7">
        <input tabindex="1" type=file name='file1' onfocus='dofocus(this);' onblur='doblur(this);'><br />
        <div tabindex=2>div</div><br />
        <input tabindex="3" type=file name='file2' onfocus='dofocus(this);' onblur='doblur(this);'><br />
        <div tabindex=4>div</div><br />
        <input tabindex="5" type=file name='file3' onfocus='dofocus(this);' onblur='doblur(this);'><br />
</form>
по примеру видно что блюр работает но только на последнем инпуте

bes 03.07.2012 18:04

devote, тогда уж и про хром отправлять, там при помощи мыши фокус вообще не установить.:)

autosoft 03.07.2012 23:34

Спасибо всем за ответы. Наверное это действительно баг.

По поводу Chromium.
Такой вариант подойдет?
<script type="text/javascript">
doclick = function (event) {

    if (navigator.userAgent.toLowerCase().indexOf('webkit') >= 0) {

        event.stopPropagation()
        event.target.focus()
    }
}
</script>
<html>
    <body>
        <form action='/'>
            <input type=file onclick='doclick(event)'>
        </form>
    </body>
</html>

Deff 03.07.2012 23:55

<script type="text/javascript">
  
function dofocus(self) {document.body.appendChild(document.createTextNode('focus('+self.name+'), '))}
function doblur (self) {document.body.appendChild(document.createTextNode('blur('+self.name+'), '))}
 
</script>
<form id="upload" method="post" enctype="multipart/form-data" action="/upload7">
<table>
   <tr><td><input type="file" name='file1' onfocus='dofocus(this);' onblur='doblur(this);'/><td>file1</td>
   </tr>
   <tr><td><input type="file" name='file2' onfocus='dofocus(this);' onblur='doblur(this);'/></td><td>file2</td>
   </tr>
   <tr><td><input type="file"  name='file3'  onfocus='dofocus(this);' onblur='doblur(this);'/></td><td>file3</td>
    </tr>
</table>
</form>

autosoft 04.07.2012 00:03

Deff
Что толку то? Мне фокус нужен на div. Ну или на td, как в последнем примере. Например так:
<script type="text/javascript">
   
function dofocus(self) {document.body.appendChild(document.createTextNode('focus('+self.name+'), '))}
function doblur (self) {document.body.appendChild(document.createTextNode('blur('+self.name+'), '))}
  
</script>
<form id="upload" method="post" enctype="multipart/form-data" action="/upload7">
<table>
   <tr><td><input type="file" name='file1' onfocus='dofocus(this);' onblur='doblur(this);'/><td tabindex=0>file1</td>
   </tr>
   <tr><td><input type="file" name='file2' onfocus='dofocus(this);' onblur='doblur(this);'/></td><td tabindex=0>file2</td>
   </tr>
   <tr><td><input type="file"  name='file3'  onfocus='dofocus(this);' onblur='doblur(this);'/></td><td tabindex=0>file3</td>
    </tr>
</table>
</form>

В результате: focus(file1), focus(file2), focus(file3),

А onblur как не было так и нет.

Deff 04.07.2012 00:14

<script type="text/javascript">
  
function dofocus(self) {document.body.appendChild(document.createTextNode('focus('+self.name+'),'))}
function doblur (self) {document.body.appendChild(document.createTextNode('blur('+self.name+'),'))}
 
</script>


<form id="upload" method="post" enctype="multipart/form-data" action="/upload7">
<table>
   <tr><td><input type="file" name='file1' onfocus='dofocus(this);' onblur='doblur(this);'/><td><input type="button" name='td1' onfocus='dofocus(this);' onblur='doblur(this);'/></td>
   </tr>
   <tr><td><input type="file" name='file2' onfocus='dofocus(this);' onblur='doblur(this);'/></td><td><input type="button" name='td2' onfocus='dofocus(this);' onblur='doblur(this);'/></td>
   </tr>
   <tr><td><input type="file"  name='file3'  onfocus='dofocus(this);' onblur='doblur(this);'/></td><td><input type="button" name='td2' onfocus='dofocus(this);' onblur='doblur(this);'/></td>
    </tr>
</table>
</form>

devote 04.07.2012 00:35

Deff,
чего бы ты не лепил, но тот вариант реально Баг, я отправил репорт в Оперу. Дальше видно будет что к чему.

Deff 04.07.2012 00:38

devote,
Да баг багом, но обычно прожект доделывают не дожидаясь правки софта?
В принципе <button> стилем под div заделать

autosoft 04.07.2012 00:47

Спасибо всем за ответы! Я как раз и с button вариант попробовал.

Мне div нужен как контейнер. В таком div свой контрол нарисован. С рисунками и со своей логикой. И ему нужно фокус принимать. И отдавать конечно тоже.
Input не подходит потому что не контейнер. Или я ошибаюсь?
Заменил input на button. Вот так:
<script type="text/javascript">

function dofocus(self) {

    document.body.appendChild(document.createTextNode('focus('+self.name+'), '))
}

function doblur(self) {

    document.body.appendChild(document.createTextNode('blur('+self.name+'), '))
}

</script>
<form action='/'>
<table>
    <tr>
        <td>
            <input type="file" name='file1' onfocus='dofocus(this)' onblur='doblur(this)'>
            <button name='button1' onfocus='dofocus(this)' onblur='doblur(this)'>Button1</button>
        </td>
    </tr>
    <tr>
        <td>
            <input type="file" name='file2' onfocus='dofocus(this)' onblur='doblur(this)'>
            <button name='button2' onfocus='dofocus(this)' onblur='doblur(this)'>Button2</button>
        </td>
    </tr>
    <tr>
        <td>
            <input type="file" name='file3' onfocus='dofocus(this)' onblur='doblur(this)'>
            <button name='button3' onfocus='dofocus(this)' onblur='doblur(this)'>Button3</button>
        </td>
    </tr>
</table>
</form>

И снова события onblur нет у <input type=file>.
Почему он нужен? <input type=file> на странице невидим и сам находится в div.
По-сути этот div - стилизованная кнопка для загрузки файлов.
Поэтому что бы его "правильно" нарисовать нужно событие onblur <input type=file>.
А его в Opera почему-то нет.


Часовой пояс GMT +3, время: 09:38.