使用jQuery获取textarea值时出错 [英] Error getting textarea value with jQuery

查看:102
本文介绍了使用jQuery获取textarea值时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我的上一个帖子失败了,所以让我们再试一次.

Ok, my last post was a failure, so let's try this again.

如果您访问www.davekiss.com并单击右上角的图标,您将看到jQuery滑块的自定义实现.单击联系"按钮,然后填写文本区域.

If you visit www.davekiss.com and click on the icon in the top right corner, you'll see a customized implementation of a jQuery slider. Click on the "Contact" button and fill out the textarea.

基本上,我想将文本区域中的值保存到javascript变量中,但是由于某种原因,该变量未定义.

Basically, what I am trying to is save the value in that textarea to a javascript variable, but for some reason, that variable is undefined.

相关代码:

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

                /*jQuery.ajax({
                   type: "POST",
                   url: "process.php",
                   data: "message=" + message,
                   success: function(msg){
                     alert( "Data Saved: " + msg );
                   }
                });*/
            });

有什么想法吗?

推荐答案

您的文本区域的名称为"message",但没有ID.您的选择器正在根据ID进行选择,但不存在此类元素.要么给textarea指定一个"message"的ID,要么更改选择器以按名称查找(以前可能更喜欢前者).

Your textarea has a name of 'message', but not an id. Your selector is selecting based on an ID, but no such element exists. Either give the textarea the id of "message", or change your selector to find by name (former is probably preferred).

这篇关于使用jQuery获取textarea值时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆