jQuery-$(document).getElementById('id').submit(function {});未定义的不是函数 [英] JQuery - $(document).getElementById('id').submit(function{}); unedifined not a function

查看:80
本文介绍了jQuery-$(document).getElementById('id').submit(function {});未定义的不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找问题或解决问题的方法,但是发现的所有查询都无济于事.

I've been searching or a solution to my problem, but none of the aswers I find are useful.

我尝试制作一个自动表单,以便在页面加载时自动提交.

I try to make an automatic form that submits itself when the page loads.

$(document).getElementById('ticketCount').submit(function(){
    $.ajax({
        method:$(this).attr('method'),
        url:$(this).attr('action'),
        data:$(this).serialize()
    })
    .done(function(data){
        $('#ticketCount').html(data);
    })
    .error(function(data){
        console.log(data);
    });
  });

我的控制台告诉我:未捕获的TypeError:未定义不是函数". 我不认为我犯了一个错误(我知道这是区分大小写的),并且我已经在同一.js中的其他地方使用了$(document).ready(),$(document).keyup(function {}).文件,因此我认为问题不在于$(document).

My console tells me that: "Uncaught TypeError: undefined is not a function". I don't think I made a mistake (I know this is case-sensitive), and I already used $(document).ready(), $(document).keyup(function{}) somewhere else in the same .js file, so I don't think the problem comes from $(document)..

我无法找到我的错误所在...

I can't ind where my mistake is...

感谢您的回答!

推荐答案

.getElementById()->这是JavaScript语法,用于获取具有特定唯一ID的DOM元素.

.getElementById() -> this is javascript syntax to get the DOM element having a particular unique Id.

在jQuery中是不同的.您需要为该DOM元素选择一个选择器

in jQuery it is deferent. You nead to have a selector for that DOM element

有很多选择器.在这里,您不需要ID SELECTOR. 即: #id

Many selectors are there. Here you nead ID SELECTOR. that is: #id

所以您需要这样写:

$('#ticketCount').submit(function(){
.............................

如果要在页面加载使用时自动提交:

If you want to submit automatically when the page load use:

window.onload = function(){
  $('#ticketCount').trigger("submit");
};

这篇关于jQuery-$(document).getElementById('id').submit(function {});未定义的不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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