admin管理员组文章数量:1402614
I am building a mobile site for a Motorola / IE 6 device.
For some reason that I can not e up with, jQuery's .select() function is working, but directly calling it in javascript is not.
<input type="text" id="lid" value="" class="as_done">
The jQuery way that works is this:
$('#lid').select();
The way that isn't working is this:
document.getElementById('lid').select();
This has me all sorts of confused. Any ideas as to why this is?
EDIT: I am not trying to do anything in jQuery. I am just trying to select the text inside the input box. I shouldn't need jQuery to do this, but the standard way is not working. .asp
I am building a mobile site for a Motorola / IE 6 device.
For some reason that I can not e up with, jQuery's .select() function is working, but directly calling it in javascript is not.
<input type="text" id="lid" value="" class="as_done">
The jQuery way that works is this:
$('#lid').select();
The way that isn't working is this:
document.getElementById('lid').select();
This has me all sorts of confused. Any ideas as to why this is?
EDIT: I am not trying to do anything in jQuery. I am just trying to select the text inside the input box. I shouldn't need jQuery to do this, but the standard way is not working. http://www.w3schools./jsref/met_text_select.asp
Share Improve this question edited Apr 20, 2012 at 18:47 teynon asked Apr 20, 2012 at 18:39 teynonteynon 8,38810 gold badges72 silver badges109 bronze badges 4- it does work -> jsfiddle/e3EKv – Isaac Fife Commented Apr 20, 2012 at 18:49
- that fiddle does not work in firefox Isaac Fife... I assume it does work in Webkit browsers... EDIT: does work in Chrome – Tobias Krogh Commented Apr 20, 2012 at 18:50
- Notice the windows-mobile / IE 6... – teynon Commented Apr 20, 2012 at 18:51
- checkout my answer below and try to natively focus the input before calling the native select – Tobias Krogh Commented Apr 20, 2012 at 18:52
3 Answers
Reset to default 2Interesting change made it work for me. Perhaps this is a bug in windows mobile IE 6?
Consider the following html:
<input type="hidden" id="lid_as" name="lid" value="1">
<input type="text" id="lid" value="" class="as_done">
Calling alert("document.getElementById('lid').name");
resulted in the message lid
. This makes me think that it is grabbing the first input box whose ID is actually lid_as.
When I moved the lid_as
input below the lid
box, the select
function works properly.
So this HTML made it work:
<input type="text" id="lid" value="" class="as_done">
<input type="hidden" id="lid_as" name="lid" value="1">
Again, this question is in relation to WINDOWS MOBILE IE 6.
$() function returns a jquery object whereas document.getElementById returns a simple DOM object.
maybe it happens due to the fact you did not call .focus() in advance
document.getElementById('lid').focus();
document.getElementById('lid').select();
this is wrapped in jQuerys .select()
本文标签: jQuery select worksbut Javascript select doesntStack Overflow
版权声明:本文标题:jQuery .select works, but Javascript .select doesnt - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744363747a2602671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论