简体   繁体   English

Select2 onchange不起作用

[英]Select2 onchange not working

When I've added select2 to all selects in my app it worked very nice except when in my select is this property(it works when I don't use select2): 当我将select2添加到我的应用程序中的所有选择中时,它工作得非常好,除了在我的select中是该属性(当我不使用select2时它可以工作):

onchange="'refresh()'"

Function refresh: 功能刷新:

function refresh()
{
    document.forms[0].submit();
}

This is how I run select2 这就是我运行select2的方式

    $("select").each(function(){
        var this1 = $(this);
        if(this1.attr('multiple')!='multiple')
        {
            this1.select2();
        }
    });

How to pass this? 如何通过? Or maybe there is some mechanism inside the select2 that deals with that kind of problems? 也许select2内部有某种机制可以解决此类问题? All kinds of suggestions are welcome:D 欢迎各种建议:D

you need to update this: $(#Select/Input Element).select2(); 您需要更新此内容: $(#Select/Input Element).select2();

 $("#select/input element").change(function () { var valueToSet = $("#select/input element").select2('data').text; $('#hiddent field to which data to be set').val(valueToSet); }); 

Not sure to understand. 不确定了解。 When one of yours selects changes, you want to call the refresh method? 当您的一个选择更改时,您要调用refresh方法吗? In that case : 在这种情况下 :

$("select").each(function(){
    var $this = $(this);
    if($this.attr('multiple')!='multiple'){
        $this.select2();
        $this.change(refresh);
    }
});

Remove single quote from onchange="'refresh()' . Try as mentioned below : onchange =“'refresh()'中删除单引号,尝试如下进行操作:

<input type="checkbox" onchange="Refresh();"/>

And your script will be defined as below : 您的脚本将定义如下:

<script type="text/javascript">

        function Refresh() {
            alert('refresh');
        }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM