模式对话框中的 FireFox 文本区域问题
我在 jQuery UI 模式对话框中有一个文本区域。 我尝试像这样更改文本框值:
1) $('#textarea').val('test value');
2) $('#textarea').text('test value');
这两者都适用于所有浏览器。除了 Firefox 之外,它只能运行一次。
当使用新值再次调用其中任何一个时,文本区域值保持不变。无论是在模式对话框打开时还是在打开它之前(它以 textarea id="textarea" 作为内容的一部分打开 - 因此在打开之前更改它的值,应该在打开时保留该值文本框)。
正如另一个线程中所建议的,我尝试在
$('#textarea').css('display', 'block');
设置文本区域的值之前和之后进行操作。
有什么线索吗?
我不明白为什么这个问题只出现在 FireFox 中 - 通常所有功能在 Firefox 中都能正常工作,但在其他浏览器中却不能。
谢谢。
I've got a textarea inside a jQuery UI modal dialog.
I tried changing the textbox value like this:
1) $('#textarea').val('test value');
2) $('#textarea').text('test value');
Both of these work in all browsers. Except in Firefox it only works ONCE.
When calling to either of these once again with a new value, the textarea value remains unchanged. No matter if this is while the modal dialog is open or prior to opening it (it opens with the textarea id="textarea" as part of the content - so changing the value of it prior to opening, SHOULD leave the value when opening the textbox).
As suggested in an other thread, I tried doing
$('#textarea').css('display', 'block');
both prior and after setting the value of the textarea.
Any clues?
I can't figure out why this issue occurs just in FireFox - usually everythings functions in Firefox but not in other browsers.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为它只能工作一次,所以它并没有完全损坏。由于您使用 Firefox 进行开发,我假设您也在使用 Firebug。您应该通过在
第一次尝试设置值之前和之后编写来尝试简单的调试。有趣的是,jQuery 能够在第一次设置后选择它。
Since it works once, its not completely broken. Since you are developing with Firefox I assume you are also using Firebug. You should try simple debugging by writing
before and after you have first time tried to set the value. It would be interesting to see will jQuery be able to select it after first time set.
这不是设置值的问题,而是dialog('open')方法在每次调用时重置这些文本区域值的问题。这似乎是 FF 和 jqueryUI 对话框之间的一些错误,因为它是几个月前开始发生的,之前工作得很好。
解决方案很简单,只需在显示对话框之后填充文本区域的值,而不是之前。
It's not the issue with setting the value, but with the dialog('open') method resetting those textarea values on each call. It's seems to be some bug between FF and jqueryUI dialog, as it started happening a few months ago, it worked fine before.
Solution is simple, just fill the values of textareas after you show the dialog, not before.
我在 Firefox 5.0.1 和 jQuery UI 1.8.14 中遇到了这个问题,
我通过在单击事件处理程序中移动 .dialog() 调用而不是创建 onload 对话框来解决这个问题。这意味着每次单击打开对话框都会重新创建整个对话框(我认为),这可能是解决文本区域问题的原因。
您的里程可能会有所不同。
I ran into this issue with Firefox 5.0.1 and jQuery UI 1.8.14
I've somehow hacked around this by moving the .dialog() call inside a click event handler instead of creating the dialog onload. This means that each click to open the dialog recreates the whole dialog (I think), and that may be what's fixing the textarea issue.
Your mileage may vary.