jQuery在jQuery函数中将可选参数设置为0

jQuery在jQuery函数中将可选参数设置为0,jquery,Jquery,我有一个非常基本的jquery函数,它接受两个参数,maxWidth和minWidth。这个 参数检查用户的浏览器大小,并根据其浏览器大小执行操作 $.fn.browserWidth = function(maxWidth, minWidth) { maxWidth = maxWidth || 1100; return document.documentElement.clientWidth >= maxWidth; return document.documentEl

我有一个非常基本的jquery函数,它接受两个参数,maxWidth和minWidth。这个 参数检查用户的浏览器大小,并根据其浏览器大小执行操作

$.fn.browserWidth = function(maxWidth, minWidth) {
  maxWidth = maxWidth || 1100;    
  return document.documentElement.clientWidth >= maxWidth;
  return document.documentElement.clientWidth <= minWidth; 
};
})(jQuery);
但是,第二个条件始终激发,但我只希望它在移动断点激发

if(browserWidth(0,1099)){ //do something }
我把第一个参数设为零是错的吗?理想情况下,我甚至不想要第一个论点 只想检查一下这种情况下的最小宽度。但我也有其他的例子
只是想检查一下maxWidth?有什么想法吗?谢谢

您可能希望接受一个对象:

$.browserWidth = function(options) {
  // Returns true if no options are passed
  var result = true;
  var width  = $(window).width();

  if('lowerThan' in options) {
    result = result && (width <= options.lowerThan);
  }

  if('biggerThan' in options) {
    result = result && (width >= options.biggerThan);
  }

  return result;
};

您的第二次
返回
将永远无法到达,因为您已经返回了上面的内容。我想您需要:
returndocument.documentElement.clientWidth>=maxWidth&&document.documentElement.clientWidth-Newb问题,但如何返回这两个参数?你能在这里包括一个代码示例newb吗?上面刚刚编辑的注释为什么这里还包括jQuery?这是一个没有任何jQuery代码的JavaScript问题。
$.browserWidth = function(options) {
  // Returns true if no options are passed
  var result = true;
  var width  = $(window).width();

  if('lowerThan' in options) {
    result = result && (width <= options.lowerThan);
  }

  if('biggerThan' in options) {
    result = result && (width >= options.biggerThan);
  }

  return result;
};
if($.browserWidth({ lowerThan: 1099 }) { // ...

if($.browserWidth({ biggerThan: 1099 }) { // ...

if($.browserWidth({ lowerThan: 2000, biggerThan: 1000 }) { // ...