0

这是 2 个输入的 2 个不同函数 - inputStringVga 和 inputStringCpu,但是它总是只加载第一个函数,即使 2 个输入具有不同的 ID(inputStringVga 和 inputStringCpu) 为什么会这样?以及如何让他们加载他们的函数而不是只加载第一个函数查询?

function lookup(inputStringVga) {
    if(inputStringVga.length == 0) {
        $('#suggestions').fadeOut(); // Hide the suggestions box
    } else {
        $.post("rpc.php", {queryStringVga: ""+inputStringVga+""}, function(data) { // Do an AJAX call
            $('#suggestions').fadeIn(); // Show the suggestions box
            $('#suggestions').html(data); // Fill the suggestions box
        });
    }
}
function lookup(inputStringCpu) {
    if(inputStringCpu.length == 0) {
        $('#suggestions').fadeOut(); // Hide the suggestions box
    } else {
        $.post("rpc.php", {queryStringCpu: ""+inputStringCpu+""}, function(data) { // Do an AJAX call
            $('#suggestions').fadeIn(); // Show the suggestions box
            $('#suggestions').html(data); // Fill the suggestions box
        });
    }
}

rpc.php 文件

$querystring = JRequest::getVar('queryStringCpu');
    if(isset($querystring)) {
if(strlen($querystring) >0) {

    $query = "SELECT cpuname FROM #__cpu WHERE cpuname LIKE '%" . $querystring . "%' ORDER BY cpuname LIMIT 50";
    $db->setQuery( $query );
    $db->query( $query ) or die('Blogai');
    $qq = $db->loadObjectList();

    foreach ($qq as $aa) {
    echo '<div class="aa">'.$aa->cpuname.'</div>';
        }
    }
}
$querystring2 = JRequest::getVar('queryStringVga');

    if(isset($querystring2)) {
if(strlen($querystring2) >0) {

    $query2 = "SELECT vganame FROM #__cpu WHERE vganame LIKE '%" . $querystring2 . "%' ORDER BY vganame LIMIT 50";
    $db->setQuery( $query2 );
    $db->query( $query2 ) or die('Blogai');
    $qq2 = $db->loadObjectList();

foreach ($qq2 as $aa2) {
    echo '<div class="aa1">'.$aa2->vganame.'</div>';
        }
    }
}
4

2 回答 2

1

从我认为你正在尝试做的事情来看,你会想要这样的东西:

<input name="'.$this->name.'" type="text" size="50" value="'.$this->value.'" id="inputStringVga" onkeyup="lookup(this.value, this.id);" /></input> <div id="suggestions"></div>

和你的 JS:

function lookup(val, id) {
    if(val.length == 0) {
        $('#suggestions').fadeOut(); // Hide the suggestions box
    } else {
        aa = {};
        aa[id] = ""+val+"";
        $.post("rpc.php", aa, function(data) { // Do an AJAX call
            $('#suggestions').fadeIn(); // Show the suggestions box
            $('#suggestions').html(data); // Fill the suggestions box
        });
    }
}

可能需要弄乱该关联数组的形成方式,但无论如何..

于 2012-11-07T16:48:07.317 回答
0

它们都是相同的功能。所以一个函数会. signature of current function因为在读取任何代码之前首先读取函数定义。

两者都有相同的签名 function lookup() ..参数的数量没有问题。

于 2012-11-07T16:27:28.450 回答