【发布时间】:2013-11-25 03:03:30
【问题描述】:
突然停止工作。
var showMyLocation = document.createElement('input');
showMyLocation.type = "checkbox";
showMyLocation.className = "checkboxForRange";
showMyLocation.id = "showMyLocation";
$$.children("#showMyLocation").html('<p style="float:left">Vis min posisjon :</p>').append(showMyLocation);
$('#' + showMyLocation.id).change(function () { //location
console.log("clicked");
if ($(this).is(":checked")) {
console.log("y");
GarageHandler.showPosition();
} else {
console.log("n");
GarageHandler.hidePosition();
}
});
这是给定代码的输出:
"clicked"
"n",
"clicked"
"n",
"clicked"
"n",
"clicked"
"n",
etc.
应该是这样的:
"clicked"
"y",
"clicked"
"n",
"clicked"
"y",
"clicked"
"n",
etc.
有谁知道怎么回事?
【问题讨论】:
-
请贴出问题中的代码和现场演示来重现问题。
-
看起来你有一个容器和一个具有相同 id 的输入字段
标签: javascript jquery checkbox