jQuery不是函数错误 [英] jQuery is not a function error

查看:87
本文介绍了jQuery不是函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这句话有什么问题?

message = $("#contact-form").find(".long-text");

if(message.val().length < 15)
{
    message.css("border","2px solid red");
    alert("Your message must be more than 15 character long");
}

我在 Firebug ?可能是什么原因?

I get message.val is not a function error in Firebug? What could be the reason?

好的,现在我的表格赢了如果我有多于或少于15个字符,请提交。我应该在这个问题上打开一个新问题,还是应该继续关注这个问题?

OK, now my form won't submit if I have more or less than 15 characters. Should I open a new question on this or should I continue on this one?

我有这个内容:

$("#contact-form").submit(function(){
  message = $("#contact-form").find(".long-text");

    if(message.val().length < 15)
    {
        message.css("border","2px solid red");
        alert("Your message must be more than 15 character long");
        return false;
    }
    else {
        Post form with Ajax ..
    }
});


推荐答案

正如您在语法荧光笔中看到的那样,引号假冒了:)丢失了双重注释。

As you can see in the syntax highlighter, the quotes went bogus :) There's a doublequote missing.

此外, val() 仅适用于输入元素(输入选择 textarea 按钮 )。如果它确实不是输入元素,那么请使用 text() 。此外,没有 length()这样的功能,你可能想使用 长度 财产。

Besides, the val() only works on input elements (input, select, textarea and button). If it is indeed not an input element, then rather use text() instead. Further there's no such function as length(), you probably would like to use the length property.

我建议你去做一些基本的< a href =http://docs.jquery.com/Tutorials =nofollow noreferrer> jQuery教程和/或去获取 jQuery book

I recommend to go get yourself through some basic jQuery tutorials and/or to go get a jQuery book.

这篇关于jQuery不是函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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