Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript/jQuery:Select on change事件未触发_Javascript_Jquery - Fatal编程技术网

JavaScript/jQuery:Select on change事件未触发

JavaScript/jQuery:Select on change事件未触发,javascript,jquery,Javascript,Jquery,我有一个问题,试图让一个函数在下拉列表的“更改”事件上附加多个单独的函数,使用for。。。在循环中。$('select')对象顶部没有方法'on'是Chrome调试器检测到的类型错误 这是我的代码:(我没有太多的JavaScript/jQuery知识,所以请耐心听我的代码) 编辑代码: $.fn.AKaizerDropdown = function (HiddenFeild) { var select_ = $(this).find('select'); var selectcount =

我有一个问题,试图让一个函数在
下拉列表的“更改”事件上附加多个单独的函数,使用
for。。。在
循环中。
$('select')
对象顶部没有方法
'on'
是Chrome调试器检测到的类型错误

这是我的代码:(我没有太多的JavaScript/jQuery知识,所以请耐心听我的代码)

编辑代码:

 $.fn.AKaizerDropdown = function (HiddenFeild) {

var select_ = $(this).find('select'); 
var selectcount = 0;
var Selecthold=new Array();

select_.each(function () {

    $(this).on('change', function () { //everything runs fine except dropdownlist doesn't enter into this event when an item is chosen
        var SelectedIndex = this.selectedIndex;
        Selecthold[selectcount] = [this.id, Selectedindex];

    });

});

var button_ = $(this).find('input')
button_.on('click', function () {
    for (item in Selecthold) {
        $(HiddenFeild).val += item[0] + item[1]+','; //Assigns values to element Hiddenfeild in DOM seperated by ","
    }
});
}

有些固定的代码仍然不起作用

下面是我将其附加到popover引导程序(twitter 2.3.2)的部分

}))

因此,我的问题是如何更正上述代码以获得预期的输出(如代码中的注释)?

您正在声明

var select = $('select'); // select object assigned to variable
但随后覆盖for循环中的值

for (select in this) ...

也就是说,循环中的
select
与上面声明的不同

试试这样的东西

            select.each(function(){
                 $(this).on('change', function() {
                    var SelectedIndex = this.selectedIndex;
                    Selecthold[selectcount] = [this.id, SelectedIndex];         
                    //Select ID and Selected index assigned as an array into Selecthold Array element
                });

            })

使用的jquery版本以及您希望分配给隐藏字段的值是什么?您使用的jquery版本是什么?@Arun PJhony&Andri版本1.10.2 jquery已使用,我希望打印selecthold数组中的值,该数组包含选定元素的ID,然后是相应元素ID的选定索引(我可能必须在隐藏的feild值中添加一些观众符号)这没有attr
this.attr('selectedIndex')方法
我想你是说select@Dude!o.o我不明白它的重写是如何告诉编译器在特定元素中查找每个“select”元素的?首先,
这个
包含函数的上下文,而不是jQuery对象。其次,
中的
关键字用于枚举属性对象的属性。函数中的select变量不是属性。但无论如何,这不是您想要的方式。请尝试
select.each(function(){$(this).on('change',function(){/*您的回调代码*/});
hey thanx,我没有意识到“var select=$('select');”返回一个数组对象而不是单个对象,这在for..in循环中使用时没有多大意义,因此我在原始帖子中对其进行了修复,但它仍然有效:Si已将修复代码中的哪些部分解释为commentsthanx,我编辑了原始帖子,但仍然使on change事件触发器无效,它仍然有效当我点击dropdownlist时,ent进入onchange事件,(@至少chrome调试器是这么说的)只要console.log(选择)变量see you get1 tags未能在30000毫秒内呈现,当我在drop Downlist上选择一个项目时出现错误似乎仍然有效,我认为最后一部分是问题所在,但我不知道如何更正它,否则我可能会弄乱其他试图更改默认弹出jscript的弹出窗口?
for (select in this) ...
            select.each(function(){
                 $(this).on('change', function() {
                    var SelectedIndex = this.selectedIndex;
                    Selecthold[selectcount] = [this.id, SelectedIndex];         
                    //Select ID and Selected index assigned as an array into Selecthold Array element
                });

            })