Getting Textarea Value with jQuery

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

This is driving me crazy - why doesn't my code work?

Click               jQuery("a#send-thoughts").click(function() {                 var thought = jQuery("textarea#message").val();                 alert(thought);             }); 

alerts undefined.

http://jsfiddle.net/q5EXG/

回答1:

you have id="#message"... should be id="message"

http://jsfiddle.net/q5EXG/1/



回答2:

By using new version of jquery (1.8.2), I amend the current code like in this links http://jsfiddle.net/q5EXG/97/

By using the same code, I just change from jQuery to '$'

Click   $('#send-thoughts').click(function() { var thought = $('#message').val();   alert(thought); }); 


回答3:

It can be done at easily like as:

     Click                $("a#send-thoughts").click(function() {             var thought = $("#message").val();             alert(thought);         }); 


回答4:

change id="#message" to id="message" on your textarea element.

and by the way, just use this:

$('#send-thoughts') 

remember that you should only use ID's once and you can use classes over and over.

https://css-tricks.com/the-difference-between-id-and-class/



回答5:

try this:

Click               jQuery("a#send-thoughts").click(function() {                 //var thought = jQuery("textarea#message").val();                 var thought = $("#message").val();                 alert(thought);             }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!