YUI 2とYUI3でonChange関数のコードを書く方法。 YUIでonChange in YUI
jQuery(':input[type=radio]').change(function(){
var aType=jQuery(this).val();
var numT= aType==1 ? "3" : "6" ;
var aWidth=aType==1 ? "330px" : "660px" ;
});
YUI 2とYUI3でonChange関数のコードを書く方法。 YUIでonChange in YUI
jQuery(':input[type=radio]').change(function(){
var aType=jQuery(this).val();
var numT= aType==1 ? "3" : "6" ;
var aWidth=aType==1 ? "330px" : "660px" ;
});
3(活発に開発しなくなった、使用YUI 3)YUI 2.9で
Y.all('input[type=radio]').each(function (node) {
node.on('change', function() {
var val = this.get('value');
...
});
});
// or
Y.all('input[type=radio]').on('change', function (e) {
var val = e.currentTarget.get('value');
...
});
// typical implementations alias Event or Event.on and
// Selector.query to shorter names
YAHOO.util.Event.on(
YAHOO.util.Selector.query('input[type=radio]'), 'change', function (e) {
var val = this.value;
...
});
ありがとう!しかし、JSFiddleでこれを試してみたところ、両方の値1,2がURL http://jsfiddle.net/wasim117/cEYBv/ –
残念です!私はnodelist.on()を決して使用しないという私のルールを破った。あなたが両方の価値を持っている理由は、ノードリストサブスクリプションの「this」は、イベントを受け取った個々のノードではなく、ノードリストです。しかし、e.currentTargetはノードです。コードスニペットを更新しました。 – Luke
ありがとう、私はまだ2.9を使用しており、あなたのソリューションはうまくいきます! BTW。また、.on(..)の代わりに.addListener(..)を使用することもできます。 – Kostanos
これは役立つかもしれない:http://stackoverflow.com/questions/1215012/yui-3-programmatically-fire-change-event –