デフォルトのアクションとイベントの伝播をキャンセルするためのものです
問題は、2 つの があり、「他のfunction
」ものに影響を与えることを期待していることです。ステートメントは、最も近いに適用されます。この場合、これは に渡されたものです。return false
return
function
.each()
に使用するreturn false
には、それだけで.click()
使用する必要があります。function
$("button").click(function () {
// either here...
$("div").each(function (index, domEle) {
// ...
});
// ...or here
});
に依存しているように見えるので.each()
、必要に応じて変更できる変数を作成し、最後にそれを返す必要があります。
$("button").click(function () {
var clickResult; // `undefined` = "no change"
$("div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "yellow");
if($(this).is("#stop")) {
$("span").text("Stopped at div index #" + index);
clickResult = false;
return false; // remove if you want the `.each()` to continue regardless
}
});
return clickResult;
});