无法调用$(document).ready()中的javascript函数

时间:2015-03-23 19:15:19

标签: javascript jquery html

我有一些代码:

     $(document).ready(function(){  
           $(":button").click(function(){
                alert("here");
                getDetails();
    });             
});

在getDetails()函数中,我获取表单数据并执行$ .post来获取一些数据。我最初在.click()事件中直接拥有当前在getDetails中的所有代码,并且它以这种方式工作,但我需要通过几个不同的东西调用该代码,所以我需要不绑定到具体事件。页面进入click()函数,因为我的警报显示,但它没有到达getDetails函数。有任何想法吗?单击按钮时没有控制台错误或警告。

getDetails()中的代码:

function getDetails(){
        alert("inside getDetails");
        var field1 = document.getElementById('field1').value;
        var oper1 = document.getElementById('oper1').value; 
        var value1 = document.getElementById('value1').value; 
        var field2 = document.getElementById('field2').value; 
        var oper2 = document.getElementById('oper2').value; 
        var value2 = document.getElementById('value2').value;
        var field3 = document.getElementById('field3').value; 
        var oper3 = document.getElementById('oper3').value;
        var value3 = document.getElementById('value3').value;
        var rsCount = document.getElementById('resultSetCount');

        var formData = {"field1":field1, "oper1":oper1, "value1":value1, "field2":field2, "oper2":oper2, "value2":value2, "field3":field3, "oper3":oper3, "value3":value3, "rsCount":rsCount};
        $.post("<%=request.getRequestURL().toString()%>getInfo.jsp", formData, function(response){getXML(response)});
    }

0 个答案:

没有答案