JQuery val() does not work for textarea in Opera

后端 未结 10 967
盖世英雄少女心
盖世英雄少女心 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:12

    val() and text() in jquery works correctly, but after setting value of textarea you need to rerender textarea, you can do this setting css property in such way

    if ($.browser.opera)
        $('textarea').val(someText).css({display:block});
    else
        $('textarea').val(someText);
    

    Hello from Russia. Sorry for my english =)

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

    I fix this using this in textarea

    $("#descripcion").keydown(function(){
         $("#descripcion").css("display","block");
    });
    

    put at end of script. I am sorry for my english

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

    Textarea doesn't have a value attribute. Try to use

    $('#txtDescription').text();
    
    0 讨论(0)
  • 2021-01-12 12:22

    I've found, in Chrome 6.0.472.59, Firefox 3.6.9 and Opera 10.62, all on Ubuntu 10.04, that textarea does have/use the .val() attribute. On the off-chance that some other browsers don't, or might not, I put together this jsbin demo. I used an if/else block to cover both approaches, though. Just in case...

    $(document).ready(
      function() {
      $('form').submit(
        function() {
    
          if ($('textarea').val()) {
            var means = 'val()',
            textValue = $('textarea').val();
          }
          else {
            var means = 'text()',
            textValue = $('textarea').text();
          }
    
          alert('(' + means + ') ' + textValue);
    
          return false;
        }
        );
      }
      );
    

    This Stackoverflow question (jQuery get textarea text) also suggests that it should be possible and reliable, as does the first commenter on the API page for Val(), at jQuery.com.

    Note, as regards Opera: the jsBin demo only worked once I'd deactivated the developer tools (for whatever reason). It might be worth turning off Dragonfly (if it's running), and then refreshing the demo page (or, obviously, your own test page) to see if it makes a difference. Either way, it's always worth clearing your cache to make sure the most up-to-date version of the files are being used.

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