最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jQuery .select works, but Javascript .select doesnt - Stack Overflow

programmeradmin7浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 2

Interesting 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()

发布评论

评论列表(0)

  1. 暂无评论