小编Chr*_*nes的帖子

在输入标记上使用autofocus属性时,不会调用onfocus

在以下示例中,我只获得一个警告框.我读到焦点是在JavaScript代码执行之前.有没有办法让这个工作?

<input id="i" type="text" autofocus onfocus="alert(1)">

<script type="text/javascript">
document.getElementById('i').addEventListener('focus', function() {
    alert(2);
}, false);
</script>
Run Code Online (Sandbox Code Playgroud)

(我只在Safari中测试过这个)

编辑:我显然可以这样做(Prototypejs选择器):

var autofocusElement = $$('input[autofocus]')[0];
callListener(autofocusElement);
Run Code Online (Sandbox Code Playgroud)

但与仅添加事件监听器相比,它看起来很丑陋.

编辑:

不要担心自动聚焦属性缺乏浏览器支持.它很容易解决,就像我在下面的链接中所做的那样.我可以看到,这个问题也是最好的解决方案.我的问题是,如果我能够比不必手动调用监听器那么难看.

http://jsfiddle.net/tellnes/7TMBJ/3/

它在Firefox 3.6中运行良好,因为Firefox不支持自动对焦.但是在支持自动对焦的Safari中,并不是所谓的事件.

javascript html5 javascript-events autofocus

6
推荐指数
1
解决办法
5300
查看次数

是否可以使用CSS3过渡来为米标签的值设置动画?

如果值改变,是否可以使用css将视觉变化设置为米/进度标记的动画?

像这样的东西

-webkit-transition: all 1s linear;
Run Code Online (Sandbox Code Playgroud)

要么

-webkit-transition: meter-value 1s linear;
Run Code Online (Sandbox Code Playgroud)

html5 css3

5
推荐指数
2
解决办法
2253
查看次数

标签 统计

html5 ×2

autofocus ×1

css3 ×1

javascript ×1

javascript-events ×1