简体   繁体   English

如何在选择的原型javascript选择框中触发onchange事件?

[英]how to fire onchange event in chosen prototype javascript select box?

I am using chosen prototype for select box. 我正在使用选择的原型选择框。 Now i want to fire onchange event on that select box. 现在我想在该选择框上触发onchange事件。 here is the link for chosen prototype 这是选择原型的链接

How to do this. 这个怎么做。 please help me. 请帮我。

<script type="text/javascript" src="/js/Event.simulate.js"></script>
<script src="/js/prototype.js" type="text/javascript"></script>
<script src="/chosen/chosen.proto.js" type="text/javascript"></script>


<div class="side-by-side clearfix" style="margin-bottom:14px;">

        <select data-placeholder="Select Loacation"  class="chzn-select" tabindex="2" name="source">
          <option value="">Select Loacation</option>
          <option value="">option1</option>
          <option value="">option2</option>
        </select>
  </div>



Event.observe($(".chzn-select"),'change', function(){

//alert($(".chzn-select").chosen());

})

In this line you have used $() with a class name, which it does not support. 在这一行中,您使用$()带有类名的$() ,它不支持。

Event.observe($(".chzn-select"),'change', function(){

A class name can be used multiple times so an array is returned from $$() , here is one way to work with arrays. 类名可以多次使用,因此从$$()返回一个数组,这是一种使用数组的方法。

$$(".chzn-select").invoke('observe', 'change', function() {
    ...
});

I haven't used Chosen before; 我之前没有使用过选择; it's instructions say it needs to be setup so you might have to do this outside of the change event. 它的说明说它需要进行设置,因此您可能必须在更改事件之外执行此操作。

document.observe('dom:loaded', function() {
    $$(".chzn-select").each(function(select) {
        new Chosen(select);
    });
});

use the "addEventListener" method on the select box object. 在选择框对象上使用“addEventListener”方法。

EDIT - here's an example: 编辑 - 这是一个例子:

document.getElementById('selecboxid').addEventListener('change', SomeFunction(), false);

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

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