[英]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.