Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

javascript - selObj.fireEvent is not a function

We have this function on a js file to pull a menu tree when users click on the parent item:

function menusel(unid) 
{   
    //if its in the array, deactivate it and take it out
    var index = inarray(unid,selectedarray);

    //first arrange the array
    if(index)
    {
        selectedarray[index] = 0;
    }
    else
    {
        //we have restrictions
        if(treeRestrictMode==1)
        {
            //now check its not in the array of items not allowed to b picked
            if(inarray(unid,nonSelArr))
            {
                alert('This Item is Unselectable'); 
                return;
            }       
        }
        
        //if we are in unique tree mode, can only select one
        if(treeSingleMode==1)
        {       
            //check for a non zero value, and deselect it [recursively]#
            for(var x=0;x<selectedarray.length;x++)
            {
                if(selectedarray[x]!=0)
                {   
                    //alert(unid+' '+selectedarray[x]);
                    menusel(selectedarray[x]);
                }
            }
        }
        
        selectedarray.push(unid);
    }
    
    sel_unselect(unid,index);

    //if we have an override function, it means we will assume that the parent page
    //as an input type function called treeSelFunc which takes the id and takes care of the rest
    if(overrideFunction!='')
    {
        parent.parent.treeSelFunc(unid,selName);
        return;
    }

    if(treeSingleMode!=1)
    {
        var selObj = emptySel(0);//set txt will fill it for us
    }
    else
    {
        var selObj = parent.parent.MM_findObj(selName);
        
        //see if we have options..will need to empty them
        if(selObj.size>1)
        {
            emptySel(1);
        }
        else
        {
            selObj.value=0;
        }
        
    }
    setTxt(selObj);
    selObj.fireEvent('onchange');   
}

which we call like this on a page as this:

<a id="troot[VMENU]_040" onclick="menusel(40);" class="sel">All</a>

And we are getting this: Uncaught TypeError: selObj.fireEvent is not a function

It used to work on an older browser version (I think with explorer 8) but now is not working any more using Chrome. Any ideas why?

question from:https://stackoverflow.com/questions/65830940/selobj-fireevent-is-not-a-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The fireEvent method is a proprietary Microsoft Internet Explorer alternative to the standard EventTarget.dispatchEvent() method.

Use the dispatchEvent method instead.

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...