how to get the value of a textarea in jquery?

前端 未结 12 2068
甜味超标
甜味超标 2020-11-27 17:55

i have this form and im trying to get the value from the text area. for some reason it doesn\'t want to.

相关标签:
12条回答
  • 2020-11-27 18:25

    You need to use .val() for textarea as it is an element and not a wrapper. Try

    $('textarea#message').val()
    

    Updated fiddle

    0 讨论(0)
  • 2020-11-27 18:25

    You don't need to use textarea#message

    var message = $('textarea#message').val();
    

    You can directly use

    var message = $('#message').val();
    
    0 讨论(0)
  • 2020-11-27 18:29

    You can directly use

    var message = $.trim($("#message").val());
    

    Read more @ Get the Value of TextArea using the jQuery Val () Method

    0 讨论(0)
  • 2020-11-27 18:34

    Value of textarea is also taken with val method:

    var message = $('textarea#message').val();
    
    0 讨论(0)
  • 2020-11-27 18:34

    $('textarea#message') cannot be undefined (if by $ you mean jQuery of course).

    $('textarea#message') may be of length 0 and then $('textarea#message').val() would be empty that's all

    0 讨论(0)
  • 2020-11-27 18:34

    You can also get the value by element's name attribute.

    var message = $("#formId textarea[name=message]").val();
    
    0 讨论(0)
提交回复
热议问题