返回false/web开发javascript/jquery
我有一些这样的代码示例 ----------------------第一个例子-----------------返回false/web开发javascript/jquery,javascript,jquery,Javascript,Jquery,我有一些这样的代码示例 ----------------------第一个例子----------------- var rightFunction=function() { if (options.currentPage < options.numberOfPages) { options.currentPage += 1; ajaxConnection(); } return false;
var rightFunction=function() {
if (options.currentPage < options.numberOfPages) {
options.currentPage += 1;
ajaxConnection();
}
return false;
};
$('#newsContainer #rightSlider').click(rightFunction);
$('#rightSliderHigh').click(rightFunction);
$('#rightSliderPagination').click(function(){
if (parseInt(_pagina_last_link.html()) >= options.numberOfPages) {
return false;
}
_first_page_num = parseInt(_pagina_first_link.html());
paginationGenerator(_first_page_num + options.centerNumber - 1);
$('#slider-inner').slider("option", "value", _first_page_num + options.centerNumber - 1);
return false;
});
$(".download").click(function(){
if($(this).attr('goToPage')=='true') {
var url=$(this).attr('href');
document.location.href=url;
return false;
}
var _this = $(this);
var thistext = $("#bg-download-box").html();
var _whattoshow = $(this).parent().find(".what-to-show").html();
if (_whattoshow){
$("#bg-download-box form").html(_whattoshow);
}
else{
$("#bg-download-box").html("<div id='bg-download-box-inner' style='height:132px'></div>");
}
if ($(".reccomend-box").length != 0){
$("#rightColumn").css("z-index",99999);
}
$("#bg-download-box").show();
var whattocopy = $("#bg-download-box");
$(whattocopy).insertAfter(_this);
$("ul#songs-list").css("z-index","99999");
$("ul#songs-list li.b-a-r").removeClass("emph");
$(this).parent().parent().parent().addClass("emph");
return false;
});
------------------------第三个例子----------------------
var rightFunction=function() {
if (options.currentPage < options.numberOfPages) {
options.currentPage += 1;
ajaxConnection();
}
return false;
};
$('#newsContainer #rightSlider').click(rightFunction);
$('#rightSliderHigh').click(rightFunction);
$('#rightSliderPagination').click(function(){
if (parseInt(_pagina_last_link.html()) >= options.numberOfPages) {
return false;
}
_first_page_num = parseInt(_pagina_first_link.html());
paginationGenerator(_first_page_num + options.centerNumber - 1);
$('#slider-inner').slider("option", "value", _first_page_num + options.centerNumber - 1);
return false;
});
$(".download").click(function(){
if($(this).attr('goToPage')=='true') {
var url=$(this).attr('href');
document.location.href=url;
return false;
}
var _this = $(this);
var thistext = $("#bg-download-box").html();
var _whattoshow = $(this).parent().find(".what-to-show").html();
if (_whattoshow){
$("#bg-download-box form").html(_whattoshow);
}
else{
$("#bg-download-box").html("<div id='bg-download-box-inner' style='height:132px'></div>");
}
if ($(".reccomend-box").length != 0){
$("#rightColumn").css("z-index",99999);
}
$("#bg-download-box").show();
var whattocopy = $("#bg-download-box");
$(whattocopy).insertAfter(_this);
$("ul#songs-list").css("z-index","99999");
$("ul#songs-list li.b-a-r").removeClass("emph");
$(this).parent().parent().parent().addClass("emph");
return false;
});
$(“.download”)。单击(函数(){
if($(this.attr('goToPage')=='true')){
var url=$(this.attr('href');
document.location.href=url;
返回false;
}
var_this=$(this);
var thistText=$(“#bg下载框”).html();
var_whattoshow=$(this.parent().find(“.what to show”).html();
如果(什么节目){
$(“#bg下载框格式”).html(_whattoshow);
}
否则{
$(“#bg下载框”).html(“”);
}
如果($(“.reccomend box”).length!=0){
$(#rightColumn”).css(“z-index”,99999);
}
$(“#bg下载框”).show();
var whattocopy=$(“#bg下载框”);
$(whattocopy)。在(\u this)之后插入;
$(“ul#songs list”).css(“z-index”,“99999”);
$(“ul#songs list li.b-a-r”).removeClass(“emph”);
$(this.parent().parent().parent().addClass(“emph”);
返回false;
});
在这些函数的末尾使用Why is return false。请有人解释一下return false的用途。在示例2和3中,第一个return false会阻止函数中任何后续代码的执行
在示例1中,它实际上什么都不做。有时我自己也会这样做,只是出于习惯和清晰的目的,以便未来的程序员阅读我的代码。请解释一下,为了让人们更容易帮助您,您的代码应该做些什么。代码来自哪里?我认为这些函数没有任何理由需要返回任何值。以下是相关的jQuery文档:@Khalid,我认为wall o'代码与问题无关。OP只关心
返回false
,以免触发默认行为。