JQuery val() does not work for textarea in Opera

后端 未结 10 966
盖世英雄少女心
盖世英雄少女心 2021-01-12 11:33

I am displaying a modal dialog using jQuery. This dialog has a textarea control on it. But while submitting this dialog, the value of this textarea

相关标签:
10条回答
  • 2021-01-12 12:00

    Have you tried .attr("text") or .attr("value")? I'm unable to test this but this would seem logical to me.

    If it doesn't then let me know and I'll remove this answer.

    0 讨论(0)
  • 2021-01-12 12:03

    In opera for getting the value or a textarea works only:

    document.getElementById("description").value;

    strange is that $("textara#description").val("") works (set method)

    0 讨论(0)
  • 2021-01-12 12:05

    Select <textarea> by attribute name instead of id.

    <textarea id="txtDescription" name="txtDescription"></textarea>
    <script>
      jQuery("textarea[name='txtDescription']").val();
    </script>
    
    0 讨论(0)
  • 2021-01-12 12:06

    you may have come across a very obscure bug referred to in a blog post on the Opera sitepatching blog 1 as "PATCH-287, Hack to make script see typed value in TEXTAREA on blog.ebuddy.com. Opera fails to read correct value from a previously hidden textarea".

    I'm a little bit reluctant to recomment workarounds without seeing the full code though.

    0 讨论(0)
  • 2021-01-12 12:08

    I use this workaround:

    
    if (window.opera)
    {
      document.addEventListener('focus', function(event){
        if (event.target instanceof HTMLTextAreaElement)
        {
          event.target.contentEditable = true;
          event.target.contentEditable = false;
        }
      }, true);
    }
    
    0 讨论(0)
  • 2021-01-12 12:10

    Good day people,

    I too have the same problem with Opera 10.63 and Windows.

    The hack suggested by Javier Canizalez works, but only as long as I don't reuse the dialog (and the textarea) again. However, this is not the case. With his hack, after the page is loaded and I click on an item, I display a dialog that was previously hidden (display:none) with textarea inside it. Everything works fine the first time (with the hack). After closing the dialog /* $(dialog).hide()); */ and reusing it again by clicking on another item, the hack does not work anymore and javascript/jQuery does not get the new typed value anymore until a full page reload.

    I found at one of the links given above that the guys at opera have fixed that problem: PATCH-287 But it does not seems fixed to me :) I wrote a question there and will see if they'll reply: opera patch-287

    Has someone managed to get a workaround this?

    Thank you and best regards.

    0 讨论(0)
提交回复
热议问题