【问题标题】:checkbox onchange event android cordova visual studio not working复选框onchange事件android科尔多瓦视觉工作室不工作
【发布时间】:2018-05-09 19:22:52
【问题描述】:

我不明白。我正在使用 Visual Studio 2017 和 Cordova 创建一个应用程序。由于某种原因,onclick 和 onchange 事件都不会被触发。

这是我的代码。难道我做错了什么?其他 onclick 事件工作正常,将其更改为 onchange 事件不起作用。我已经尝试了我能想到的一切。我唯一能想到的是它不起作用,因为我使用 javascript 填充 div,然后尝试在 javascript 中执行另一个操作。这会导致这个吗?我该如何解决?

$(document).ready(function() {
var id = localStorage.getItem("id");


$.getJSON("https://url.nl/interesses_json.php?id="+id, function(result) {
$.each(result, function(i, field) {

if(field.acceptsallworkgroups == '1'){ 

var interesses = '<div class="onoffswitch"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" class="alles"   checked><label class="onoffswitch-label" for="myonoffswitch"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div>'
      var interlist = '<div style="padding-left: 30px;padding-top: 20px; height: 200px;">Je staat momenteel open voor voorstellen uit alle categorieën</div>'
     }else{
      var interesses = '<div class="onoffswitch"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" class="alles"  ><label class="onoffswitch-label" for="myonoffswitch"><span class="onoffswitch-inner"></span><span class="onoffswitch-switch"></span></label></div>'
var interlist = '<div style="padding-left: 30px;padding-right: 30px; padding-bottom: 20px;"><div style="padding-left: 30px; border-radius: 8px;background: linear-gradient(#F5C436, #F3B23F); height: 40px; color: white; padding-top: 10px;"><div style="color: white; float:left;">'+field.name+'</div><div style="color: white; float:right; padding-right: 20px;"><a href="javascript:void(0);"   id="detail'+field.id+'"> v </a></div></div><div id="showdetail'+field.id+'" style="display: none;background-color:#f7f7f7; padding-top: 20px; padding-left:30px;">'+field.comments+'</div></div>'
     }
document.getElementById('int').innerHTML = "<div style='padding-left: 30px;'><div style='float: left; padding-top: 10px; '> Ik sta open voor alles: </div><div  style='float: right; padding-right: 40px;'> " +interesses+"</div></div>"

document.getElementById('intlist').innerHTML += interlist




}); 
$( ".alles" ).click(function() {
console.log("hoi")
});
});

<style>
.onoffswitch {
    position: relative; width: 96px;
    -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
    display: none;
}
.onoffswitch-label {
    display: block; overflow: hidden; cursor: pointer;
    border: 1px solid #FFFFFF; border-radius: 20px;
}
.onoffswitch-inner {
    display: block; width: 200%; margin-left: -100%;
    transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
    display: block; float: left; width: 50%; height: 35px; padding: 0; line-height: 35px;
    font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
    box-sizing: border-box;
}
.onoffswitch-inner:before {
    content: "Ja";
    padding-left: 15px;
    background-color: #E38700; color: #FFFFFF;
}
.onoffswitch-inner:after {
    content: "Nee";
    padding-right: 15px;
    background-color: #EEEEEE; color: #999999;
    text-align: right;
}
.onoffswitch-switch {
    display: block; width: 18px; margin: 8.5px;
    background: #FFFFFF;
    position: absolute; top: 0; bottom: 0;
    right: 57px;
    border: 2px solid #FFFFFF; border-radius: 22px;
    transition: all 0.3s ease-in 0s; 
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
    margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px; }

</style>
<div class='row'>
<div id='int' style='padding-top: 20px; padding-bottom: 0px;'>

</div>
</div>

【问题讨论】:

    标签: android jquery visual-studio cordova


    【解决方案1】:

    总是把事件放在文档上,指明你想要的元素:

    $(document).on('click',  ".alles", function() {
        console.log("hoi");
    });
    

    这样您可以防止事件在动态元素中起作用。

    【讨论】:

    • 很遗憾没有效果 :(
    • 您正在使用两个类: 将输入更改为:
    猜你喜欢
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2016-04-05
    相关资源
    最近更新 更多