开发者

XUL's textbox and jQuery, how to retrieve value?

I've a XUL document with a textbox:

<textbox id="prod_text" />
开发者_如何学编程

I tried to retrieve the value that was manually added on it using jQuery, in this way:

Firebug.Console.log($("textbox#prod_text").attr('value'));

But it doesn't work! It returns an empty value... What is wrong?

Edit: I'm working in a Firefox extension... that's where my functions was associated to an event. I'm trying to access data in a XUL document...


Have you tried using jquery's "val" method?

http://api.jquery.com/val/

This should get the value of the text box. It can also be used to set the value (if you so desire).


I really don't know why, but in this way it worked (adding an hidden label, synchronized with the textbox):

<textbox id="prod_text" onkeyup="var t = document.getElementById('prod_text_hid'); t.value = value;"/>
<label value="label" hidden="true" id="prod_text_hid"/>

And then:

Firebug.Console.log($("#prod_text_hid").attr('value'));

...returns the right value!!!

Do you have an idea of the reason? It's an ugly solution, but it works... :-(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜