jQueryはtextareaテキストフィールド値を取得します



Jquery Get Textarea Text Field Value



.val jQuery()メソッドは、フォーム要素の値を取得するように設計されていますが、textareaフォーム要素を()メソッドにして直接.valを取得することもできます。ただし、textareaが二重にラベル付けされているため、.text()または.html()メソッドも情報を取得できますが、.val()は取得メソッドの値専用であるため、これは取得をお勧めしません。比。 text()または.html()の方が信頼性が高く、.text()および.html()は値を取得できない場合があります。

$(function(){
  1. $ ( '# Demo') val (123). // modify the contents of the textarea to 123



  2. $ ( '# Demo') text (456). // The content of the textarea revised to 456

  3. // display on the last page is acquired and 123



  4. // You can try to reverse the order of modification of the above process, the final result was 123

  5. // pop textarea value alert ($ ( '# demo') val ().)

  6. })



  7. test

  8. if($('#txt').val().trim().length == 0) {
    return
    }

trim () Clear a space character before and after the text