下拉菜单上的Onclick事件没有被调用

onclick event on dropdown is not getting called

本文关键字:调用 事件 Onclick 下拉菜单      更新时间:2023-09-26

我正在动态地将以下组合框"Select Page "添加到jsp页面,它在更改时填充另一个名为"Objects"的组合框。选择页面下拉菜单正确加载内容,但没有触发事件。即populateObjects。我在populateObjects()函数中保持了警报,这表明它甚至没有调用这个警报。请帮助。

//Select Page
       var cell4 = row.insertCell(3);
       var element4 = document.createElement("select");
       element4.setAttribute('id', 'selPageRow' + rowCount);
       element4.setAttribute('name', 'selPageRow' + rowCount);
       element4.setAttribute('onClick', 'javascript:populateObjects(this.options[this.selectedIndex].innerHTML,'+rowCount+');');
       var PageArray = getPages();
       var option = document.createElement("option");
       option.text = "Select..."; 
       option.value = "select"; 
       element4.options.add(option);
       for(var i=0;i<PageArray.length;i++)
           {
               var option = document.createElement("option");
               option.text = PageArray[i].attributes[0].nodeValue; 
               option.value = PageArray[i].attributes[0].nodeValue;  
               element4.options.add(option);
           }
       cell4.appendChild(element4); 
// Code for populating Object dropdown
    function populateObjects(selectedValue,rowCount)
    {
        alert(selectedValue);
        var SelBox = document.getElementById('selObjRow' + rowCount);
        removeAllOptions(SelBox);
        var ObjArry = getObjects(selectedValue);
        var option = document.createElement("option");
        option.text = "Select..."; 
        option.value = "select"; 
        SelBox.options.add(option);
        if(ObjArry.length>0)
        {
            for(var i=0;i<ObjArry.length;i++)
               {
                   var option = document.createElement("option");
                   option.text = ObjArry[i].attributes[0].nodeValue; 
                   option.value = ObjArry[i].attributes[0].nodeValue;  
                   SelBox.options.add(option);
               }
        }
        else
        {
            var option = document.createElement("option");
            option.text = "None"; 
            option.value = "none"; 
            SelBox.options.add(option);
        }
        cell5.appendChild(SelBox);
    }

onClick事件更改为onChange事件

   element4.setAttribute('onChange', 'javascript:populateObjects(this.options[this.selectedIndex].innerHTML,'+rowCount+');');