jQuery函数返回undefined?为什么?

时间:2011-07-22 20:48:08

标签: javascript jquery ajax dom undefined

http://www.kupe.nl/badkamer3.html

我无法使用这个在线代码,只是不会制作代码块...)

jQuery函数loadingAjax()未定义?填写所有无线电时调用此操作。此表单的某些部分使用另一个函数进行检索。

如果你想参加考试

选择“纽约”模式。并继续填写表格..并提交按钮

请帮忙,

由于

js code:

<script type="text/javascript">
$(document).ready(function(){

$("#ptmodel label").click(function() {

    var mainImage = $(this).attr("name");
    var targetRadio = $(this).attr("for");
        $("#main_image img").attr({ src: 'http://www.kupe.nl/media/privatetime/images/smaller/' + mainImage + '.jpg' });
    $("#" +targetRadio).attr("checked", "checked");


    var selected = mainImage;
    var selecteddataString = 'in_pt_model_label='+ selected;

    $.ajax({
    type: "POST",
    url: "badkamer_sets.php",
    data: selecteddataString,
    success: function(selected){
    $("#ptsize_check").html(selected);
        }

    });     
});

function loadingAjax(my_div){
        var size = $('input:radio[name=in_pt_artikel]:checked').val();
        var color = $('input:radio[name=in_pt_color]:checked').val();
        var model = $('input:radio[name=in_pt_model]:checked').val();

           if(model == '' || model == null){
        $('#ptmodel_check').html('<font color="red">Selecteer een Model a.u.b</font>');

        }
        if (size == '' || size == null){
         $('#ptsize_check').html('<font color="red">Selecteer een Opstelling a.u.b</font>');

        }
        if (color == '' || color == null){
         $('#ptcolor_check').html('<font color="red">Selecteer een Front a.u.b</font>');

        }
        else {

        var dataString = 'in_pt_model='+ model + '&in_pt_color=' + color + '&in_pt_artikel=' + size;
    //$("#"+div_id).html('<img src="ajax-loader.gif"> saving...');

        $('#pt_form').hide();
        $('#'+my_div).html('<img src="ajax-loader.gif"> Een moment geduld alstublieft...');


        $.ajax({
    type: "POST",
    url: "badkamer_submit.php",
    data: dataString,
    success: function(msg){
            window.location="http://www.box7shop.nl/" + msg +".html";
    }
});

    }
}
});


</script> 

(thnx everone for the responses)

我的问题解决了这个问题:

$(document).ready(function(){ 
$("#ptmodel label").click(function() {


    var mainImage = $(this).attr("name");
    var targetRadio = $(this).attr("for");
        $("#main_image img").attr({ src: 'http://www.kupe.nl/media/privatetime    /images/smaller/' + mainImage + '.jpg' });
    $("#" +targetRadio).attr("checked", "checked");

    var selected = mainImage;
    var selecteddataString = 'in_pt_model_label='+ selected;

    $.ajax({
    type: "POST",
    url: "badkamer_sets.php",
    data: selecteddataString,
    success: function(selected){
    $("#ptsize_check").html(selected)
    }

    });     
});

$("#submitimg").live("click", function() {

var size =  $('input:radio[name=in_pt_artikel]:checked').val();
var color = $('input:radio[name=in_pt_color]:checked').val();
var model = $('input:radio[name=in_pt_model]:checked').val();

if(model === '' || model === null){
        $('#ptmodel_check').html('<font color="red">Selecteer een Model a.u.b</font>');
    return false;
        }
        if (size === '' || size === null){
         $('#ptsize_check').html('<font color="red">Selecteer een Opstelling     a.u.b</font>');
    return false;
        }
        if (color === '' || color === null){
         $('#ptcolor_check').html('<font color="red">Selecteer een Front     a.u.b</font>');
        return false;
        }
        else {

        var dataString = 'in_pt_model='+ model + '&in_pt_color=' + color + '&in_pt_artikel=' + size;
    //$("#"+div_id).html('<img src="ajax-loader.gif"> saving...');

    $('#pt_form').hide();
    $('#myDiv').html('<img src="ajax-loader.gif"> Een moment geduld     alstublieft...');

        $.ajax({
    type: "POST",
    url: "badkamer_submit.php",
    data: dataString,
    success: function(msg){
            window.location='http://www.box7shop.nl/' + msg + '.html';

    }
    });
    }
});

});

2 个答案:

答案 0 :(得分:1)

看起来你需要删除最后一个“});”在文档头部的结束脚本标记之前。

变化:

    }
});



致:

    }

答案 1 :(得分:0)

当我尝试使用$ .attr()获取无效html的属性时,我曾经遇到过IE的问题。我从来没有使用过属性“for”,也不知道是否有类似的属性,但如果它是无效的,可能是原因。

尝试将其更改为rel =“”。