Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中从函数中了解对象?_Javascript_Jquery - Fatal编程技术网

如何在javascript中从函数中了解对象?

如何在javascript中从函数中了解对象?,javascript,jquery,Javascript,Jquery,我使用jquery、autocomplete和dinamicly创建的输入节点 我的第一个输入具有连接: var autocomp_art_opt = { source: "ajax_find_art.php", minLength: 2, select: function(event, ui) { $.ajax({ type: "GET", url:

我使用jquery、autocomplete和dinamicly创建的输入节点

我的第一个输入具有连接:

    var autocomp_art_opt = {
        source: "ajax_find_art.php",
        minLength: 2,
        select: function(event, ui) {
            $.ajax({
                type: "GET",
                url: "ajax_find_price.php",
                data: "art="+ui.item.value,
                cache: false,
                success: function(data){
                    $("#price1").val(data);
                }
            });
        }
    };
    $("#art1").autocomplete(autocomp_art_opt);
我有一个脚本,用于添加两个输入字段art{number}和price{number},并连接新的自动完成:

$("#art2").autocomplete(autocomp_art_opt);
$("#art3").autocomplete(autocomp_art_opt);
。。。等

但是我不能在不创建新变量autocomp_art_opt{number}的情况下在autocomp_art_opt中设置price1

如何知道函数中的对象id art{number}:

success: function(data){
    $("#price1").val(data);
}

如何在调用art5等函数时将price1更改为price5…

创建一些函数来包装对象并进行调用,然后只需使用art/price的编号调用初始值设定项即可

召唤

设置


select回调包含对事件和ui的引用。事件变量应该包含event.target,它应该是对已单击框的引用,例如$art2.autocompleteautomp\u art\u opt;请参考$art2。

ui.item.value是什么?它是输入字段中的值,用于发送到ajax\u find\u price.phpart字段=产品名称价格字段=产品价格我输入名称并自动完成帮助我查找名称。当我完成时-脚本加载此名称的价格
initializeAutocomplete(1);//$("#art1") and $("#price1")
initializeAutocomplete(5);//$("#art5") and $("#price5")
function autocomp_art_opt(number){
 return {
    source: "ajax_find_art.php",
    minLength: 2,
    select: function(event, ui) {
        $.ajax({
            type: "GET",
            url: "ajax_find_price.php",
            data: "art="+ui.item.value,
            cache: false,
            success: function(data){
                $("#price"+number).val(data);
            }
        });
    }
 };
}
function initializeAutocomplete(num){
 $("#art"+num).autocomplete(autocomp_art_opt(num));
}