[英]Triggering checkbox onchange event in chrome using bookmarklet only
[英]onchange event is not fire on asp checkbox in chrome only
在Chrome中这对我不起作用
<asp:CheckBox ID="chkFullReIndex" runat="server" ClientIDMode="Static" onchange="funCalled();" />
<script>
function funCalled() {
if ($('#chkFullReIndex')[0].checked) {
alert('check box checked')
}
else {
alert('check box not checked')
}
}
</script>
这在Firefox(21.0)中工作正常,但在chrome(版本27.0.1453.94 m)中则无法工作
任何想法都一样
当使用行内事件注册,您可以发送this
给函数:
<asp:CheckBox ID="chkFullReIndex" runat="server" ClientIDMode="Static" onchange="funCalled(this);" />
和js一样:
function funCalled(obj) {
// this is present in the event handler and is sent to the function
// obj now refers to the CheckBox, so we can do
if (obj.checked) {
alert('check box checked')
} else {
alert('check box not checked')
}
}
我会采用这种方法,因为您正在加载jQuery并几乎没有使用它。
$('#chkFullReIndex').on('change', function(e){
var $this = ($this);
if($this.is(':checked')){
alert('It is checked!');
} else {
alert('It is not checked');
}
});
要完成跨浏览器功能,请使用此功能检查是否已选中复选框:
$("#chkFullReIndex").is(':checked')
要么
$("#chkFullReIndex").prop('checked')
尝试使用onclick
事件,例如
<asp:CheckBox runat="server" ID="chkPostback" Text="Check me" onclick="javascript:funCalled(this)"
ClientIDMode="Static" />
脚本
function funCalled(obj) {
if (obj.checked) {
alert('check box checked')
} else {
alert('check box not checked')
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.