Google Chrome breaks when onfocus sets size selection

The following Javascript to resize a select list breaks in Google Chrome. It works when pasted into a field, but when you click on it, β€œAw, Snap!” Appears. error page.

<select onfocus="this.setAttribute('size', 3);">
<option>selectList with onfocus</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>

Works well in FF and IE. This is some kind of conflict between onfocus (no problem if I implement it onClick) and setting the size attribute. I was told that it also breaks down in Safari.

Any help, ideas or workarounds are welcome.

(PS Yeh I know that this is not a very good form for resizing a pick list, but this is what the boss / client wants)

+3
source share
3 answers

:

<select onfocus="var that = this; setTimeout(function() {that.setAttribute('size', 3);}, 0);">

Chrome. Safari, , . , , setTimeout, , , Webkit.

+6

, Google Chrome .

. :

http://www.w3schools.com/TAGS/tryit.asp?filename=tryhtml_select_size

, Google Chrome. HTML Chrome.

0
source

Source: https://habr.com/ru/post/1705778/


All Articles