[英]checkbox onclick event jquery not working
I have a website that has a few dynamic boxes on. 我有一个网站上有一些动态框。 Every 15 seconds my javascript fires some ajax requests and then outputs the json replies on the page which works great. 每隔15秒,我的javascript就会触发一些ajax请求,然后在页面上输出json答复,效果很好。 My issue is with my checkbox toggle thing. 我的问题是我的复选框切换问题。
I had the on change event hooked up to a php page that would check the value and if its a 1 change to 0 and if 0 change to 1 (this controls the checkbox checked value). 我有on change事件连接到一个php页面,该页面将检查该值以及是否将其1更改为0以及是否将0更改为1(这可控制复选框的选中值)。
My issue is when I change it on another window ... it will after 15 seconds update and move to the state I change it to ... but this will then trigger the onchange event and I get a loop. 我的问题是,当我在另一个窗口上对其进行更改时……它将在15秒后更新并移至我将其更改为的状态……但这将触发onchange事件,并出现一个循环。
I need to use the onClick event to only change when it is manually clicked and not when it is automatically changed by the script. 我需要使用onClick事件仅在手动单击时更改,而在脚本自动更改时不更改。
How do I do this as onClick isnt working :/ 我如何执行此操作,因为onClick无法正常工作:/
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
$('.on_off :checkbox').iphoneStyle();
$('.disabled :checkbox').iphoneStyle();
$('.css_sized_container :checkbox').iphoneStyle({
resizeContainer: false,
resizeHandle: false
});
$('.long_tiny :checkbox').iphoneStyle({
checkedLabel: 'Very Long Text',
uncheckedLabel: 'Tiny'
});
var onchange_checkbox = ($('.onchange :checkbox')).iphoneStyle({
onClick: function(elem, value) {
Update();
}
});
function Update(){
$( "#result" ).load( "change.php");
}
</script>
It looks like there are a couple of issues with the script posted. 发布的脚本似乎有几个问题。 Could you see if this helps? 你能帮忙看看吗?
<script charset="utf-8" type="text/javascript">
$(window).load(function() {
$('.on_off:checkbox').iphoneStyle();
$('.disabled:checkbox').iphoneStyle();
$('.css_sized_container:checkbox').iphoneStyle({
resizeContainer: false,
resizeHandle: false
});
$('.long_tiny:checkbox').iphoneStyle({
checkedLabel: 'Very Long Text',
uncheckedLabel: 'Tiny'
});
var onchange_checkbox = ($('.onchange:checkbox')).iphoneStyle({
onClick: function(elem, value) {
Update();
}
});
});
function Update(){
$("#result").load("change.php");
}
</script>
try capturing the click event on the parent - 尝试捕获父项上的click事件-
var onchange_checkbox = ($('.onchange :checkbox')).iphoneStyle();
onchange_checkbox.parent()[0].click(function(e){Update();});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.