admin管理员组文章数量:1405378
I have the following bit of code to create an automatically resized text input:
// setup quick jump input
$("#goto").keydown(function(e){
var size = $(this).val().length;
// sanity
if ( size < 1 ) {
size = 1;
}
$(this).attr("size",size);
// if enter then GOTO->
if ( e.keyCode == 13 ) {
window.location.href = "/" + $(this).val();
}
});
HTML:
<input type="text" id="goto" size="1" name="goto" />
Problem: Resizing the input doesn't work in Safari or Chrome, just Firefox and Opera. I'm using jquery 1.3.2 and would like to know if it's a bug in jquery or my implementation.
EDIT: sorry I wasn't clear enough at first - it's the part where I'm trying to update the size of the input on the fly that is broken. My bad. Thanks for the feedback so far, some very useful links there.
I have the following bit of code to create an automatically resized text input:
// setup quick jump input
$("#goto").keydown(function(e){
var size = $(this).val().length;
// sanity
if ( size < 1 ) {
size = 1;
}
$(this).attr("size",size);
// if enter then GOTO->
if ( e.keyCode == 13 ) {
window.location.href = "/" + $(this).val();
}
});
HTML:
<input type="text" id="goto" size="1" name="goto" />
Problem: Resizing the input doesn't work in Safari or Chrome, just Firefox and Opera. I'm using jquery 1.3.2 and would like to know if it's a bug in jquery or my implementation.
EDIT: sorry I wasn't clear enough at first - it's the part where I'm trying to update the size of the input on the fly that is broken. My bad. Thanks for the feedback so far, some very useful links there.
Share Improve this question edited Apr 27, 2009 at 19:20 roborourke asked Apr 27, 2009 at 17:35 roborourkeroborourke 12.2k4 gold badges29 silver badges37 bronze badges4 Answers
Reset to default 3I doubt that the size attribute would work cross browser. I would switch to setting the maxlength and css width of the input field rather than changing the size attribute.
Looks like a bug/unsupported feature in webkit. Which Safari/Chrome share.
According to the jQuery documentation on keydown()
:
// Different browsers provide different codes
// see here for details: http://unixpapa./js/key.html
// ...
Have you checked the page referenced to see if Safari/Chrome/Webkit have different values for the Enter key?
The problem seems to lie in setting the size attribute. This line:
$(this).attr("size",size);
Safari nor Chrome doesn't respect some attributes. But you can set it via css element. Works good.
$(this).css("width","4em");
For example, i have noticed that onClick attribute doesn't work in Chrome when onclick is typed.
本文标签: javascriptSafari and Chrome problem editing input 39size39 attribute on the flyStack Overflow
版权声明:本文标题:javascript - Safari and Chrome: problem editing input 'size' attribute on the fly - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744322164a2600554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论