English 中文(简体)
自动包裹 目标预期错误
原标题:Autocomplete script getting Object expected error

http://www.candyundies.com/template_non_product.php"rel=“nofollow” http://www.candyundies.com/template_non_product.php, 我在搜索箱上使用自动填写稿征求建议。 我已经测试并正在使用目前版本的 Chrome、Safat、Series、Series和IE8。 然而,我注意到,在第一份信件被打入搜索箱后,我投下了一种预期的错误,但该笔文字继续徒劳地工作。 我确信,这是一种yn错,或者我忽视了一点,但我似乎无法找到问题。 任何帮助都会受到高度赞赏。

自动完成部分:

// global variables
var acListTotal   =  0;
var acListCurrent = -1;
var acDelay       = 100;
var acURL         = null;
var acSearchId    = null;
var acResultsId   = null;
var acSearchField = null;
var acResultsDiv  = null;
function setAutoComplete(field_id, results_id, get_url) {
// initialize vars
acSearchId  = "#" + field_id;
acResultsId = "#" + results_id;
acURL       = get_url;
// create the results div
$("#auto").append( <div id="  + results_id +  "></div> );
// register mostly used vars
acSearchField   = $(acSearchId);
acResultsDiv    = $(acResultsId);
// on blur listener
acSearchField.blur(function(){ setTimeout("clearAutoComplete()", 100) });
// on key up listener
acSearchField.keyup(function (e) {
    // get keyCode (window.event is for IE)
    var keyCode = e.keyCode || window.event.keyCode;
    var lastVal = acSearchField.val();
    // check an treat up and down arrows
    if(updownArrow(keyCode)){
        return;
    }
    // check for an ENTER or ESC
    if(keyCode == 13 || keyCode == 27){
        clearAutoComplete();
        return;
    }
    // if is text, call with delay
    setTimeout(function () {autoComplete(lastVal)}, acDelay);
});
}
// treat the auto-complete action (delayed function)
function autoComplete(lastValue) {
// get the field value
var part = acSearchField.val();
// if it s empty clear the resuts box and return
if(part ==   ){
    clearAutoComplete();
    return;
}
// if it s equal the value from the time of the call, allow
if(lastValue != part){
    return;
}
// get remote data as JSON
$.getJSON(acURL + part, function(json){
    // get the total of results
    var ansLength = acListTotal = json.length;
    // if there are results populate the results div
    if(ansLength > 0){
        var newData =   ;
        // create a div for each result
        for(i=0; i < ansLength; i++) {
            newData +=  <div class="unselected">  + json[i] +  </div> ;
        }
        // update the results div
        acResultsDiv.html(newData);
        acResultsDiv.css("display","block");
        // for all divs in results
        var divs = $(acResultsId + " > div");
        // on mouse over clean previous selected and set a new one
        divs.mouseover( function() {
            divs.each(function(){ this.className = "unselected"; });
            this.className = "selected";
        });
        // on click copy the result text to the search field and hide
        divs.click( function() {
            acSearchField.val(this.childNodes[0].nodeValue);
            clearAutoComplete();
        });
    } else {
        clearAutoComplete();
    }
});
}
// clear auto complete box
function clearAutoComplete() {
acResultsDiv.html(  );
acResultsDiv.css("display","none");
}
// treat up and down key strokes defining the next selected element
function updownArrow(keyCode) {
if(keyCode == 40 || keyCode == 38){
    if(keyCode == 38){ // keyUp
        if(acListCurrent == 0 || acListCurrent == -1){
            acListCurrent = acListTotal-1;
        }else{
            acListCurrent--;
        }
    } else { // keyDown
        if(acListCurrent == acListTotal-1){
            acListCurrent = 0;
        }else {
            acListCurrent++;
        }
    }
    // loop through each result div applying the correct style
    acResultsDiv.children().each(function(i){
        if(i == acListCurrent){
            acSearchField.val(this.childNodes[0].nodeValue);
            this.className = "selected";
        } else {
            this.className = "unselected";
        }
    });
    return true;
} else {
    // reset
    acListCurrent = -1;
    return false;
}
}
最佳回答

问题得到解决。 See comment by ocanal.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签