下拉菜单上的Onclick事件没有被调用
onclick event on dropdown is not getting called
我正在动态地将以下组合框"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+');');
相关文章:
- angularjs调用事件中控制器的一个函数
- CSS + jQ插件阻止AJAX调用/事件侦听器工作
- 如何使用webbrower对象中的脚本调用C#事件
- API Google Maps Javascript在上下文菜单中调用事件侦听器
- 调用事件处理程序oop内部的函数
- 砖石事件:在图像加载和布局完成后调用事件
- jwplayer在80%的视频上调用事件
- 显示和隐藏上下文菜单时的 Jstree 调用事件
- 如何只调用一次事件处理程序,而不是每次单击项目时调用事件处理程序
- 调用事件侦听器 - 两种方式之一起作用,有什么区别
- 在页面加载时调用函数,而不是在单击时调用事件
- jQuery 动态调用事件侦听器
- 在模块化 JavaScript 中调用事件
- 在Bootstrap面板展开中调用事件
- 如何根据变量指定是否可以调用事件侦听器
- 调用事件中带有参数的函数
- SelectAll不调用事件处理程序
- 可以以编程方式调用事件处理程序吗?
- JS中的函数调用事件
- Ionic 2:调用事件同时订阅和取消订阅