[英]How to fire change event in jQuery
我有一個UserControl放在asp.net的aspx頁面中。 在此UserControl中,我有一個RadioButtonList,並且在更改RadioButtonList項目時,我想執行以下jQuery函數。
$('#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");
}
});
});
只需執行以下操作即可:
$(document).ready(function () {
$('#rdlUser input').change(function () {
alert($(this).val());
});
});
為了執行事件,您可以在JQuery中使用trigger("eventname")
函數。
例
$("#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
使用生成的HTML,您無法通過使用$("#generatedid")
來觸發事件,因為第一次加載時元素不在DOM中。
您可以使用 :
$(document).on("change",".your-radio-button-class",function(){
//Make a test on the value of the select radio
if($(this).val() == "connected")
{
}
else
{
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.