2016-10-10 12 views
1

asp.netのaspxページにUserControlを配置しました。このUserControlではRadioButtonListがあり、RadioButtonList項目が変更された場合、以下のjQuery関数を実行します。jQueryで変更イベントを発生させる方法

$(document).ready(function() { 
    $('#rdlUser input').change(function() { 
     alert($(this).val()); 
    }); 
}); 
+0

_Iが__When__ function._ jQueryの下に実行したいですか? – Satpal

+0

RadioButtonListの項目の1つが選択されています。 –

答えて

1

をするためにあなたはjQueryを使ってtrigger("eventname")機能を使用することができ、イベントを実行します。

$('#rdlUser').change(function (e) { 
    alert("change function"); 
    var radioBtnId = this.id; 
    var $this = $(this); 
    radconfirm('Are you sure you want to take leave?', function(arg){ 
     if (arg == true) { 
      alert("User wants to take leave"); 
     }  
     else { 
      alert("User doesn't want to take leave"); 
     } 
    }); 
}); 
+0

私は、データベースからRadioButtonListアイテムを取り込み、RadioButtonListに4つのリストアイテムを取得します。特定のアイテムの変更イベントを発生させるにはどうしたらいいですか? –

+0

それはまったく違ったものです。あなたのラジオにいくつかのクラスを追加してください。私の答えを更新します – Alexis

+0

1.私のRadioButtonList2のクラスはありません.'alert($ this.val()) 'は空の文字列3を返しています。' alert($ this.val()) 'が起動しています4つまり、RadioButtonListの各アイテムについて –

1

単にあなたは次のように行うことができます。生成されたHTMLで

$("#id").keypress(function(){ 
 
    console.log("input keypress"); 
 
}); 
 

 
$("#btn").click(function(){ 
 
    $("#id").trigger("keypress"); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="text" id="id"> <button id="btn">Trigger keypress event</button>

UPDATE

要素が最初のロード時にDOMではないので、あなたは$("#generatedid")を使用してイベントをトリガすることはできません。

あなたは使用することができます。

$(document).on("change",".your-radio-button-class",function(){ 
    //Make a test on the value of the select radio 
    if($(this).val() == "connected") 
    { 

    } 
    else 
    { 

    } 
}); 
関連する問題