Sam*_*sel 3 javascript select google-chrome focus setattribute
以下用于调整选择列表大小的JavaScript会在Google Chrome中中断.它在Tabed into the field时有效,但点击它会产生"Aw,Snap!" 错误页面.
<select onfocus="this.setAttribute('size', 3);">
<option>selectList with onfocus</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
Run Code Online (Sandbox Code Playgroud)
在FF和IE中工作正常.这是onfocus之间的某种冲突(如果我在onClick上实现它没有问题)和设置size属性.我被告知它也在Safari中断了.
非常感谢任何帮助,想法或解决方法.
(PS Yeh我知道调整选择列表的形式不是很好,但这是老板/客户想要的)
使用select更改行:
<select onfocus="var that = this; setTimeout(function() {that.setAttribute('size', 3);}, 0);">
Run Code Online (Sandbox Code Playgroud)
它适用于Chrome.我没有在Safari中尝试,但我怀疑它也能正常工作.基本上我们在这里所做的就是使用setTimeout转义调用堆栈,这似乎解决了Webkit中的错误.