Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery上的错误_Jquery - Fatal编程技术网

jquery上的错误

jquery上的错误,jquery,Jquery,我有这个代码,但它似乎有一个错误。错误表示未捕获的typeError对象没有方法“HasScrollBar”,代码是否有问题?HasScrollbar方法声明在函数顶部,但似乎找不到它。请参见下面的代码 $.fn.HasScrollBar = function () { //note: clientHeight= height of holder //scrollHeight= we have content till this height var _elm =

我有这个代码,但它似乎有一个错误。错误表示未捕获的typeError对象没有方法“HasScrollBar”,代码是否有问题?HasScrollbar方法声明在函数顶部,但似乎找不到它。请参见下面的代码

 $.fn.HasScrollBar = function () {
     //note: clientHeight= height of holder
     //scrollHeight= we have content till this height
     var _elm = $(this)[0];
     var _hasScrollBar = false;
     if ((_elm.clientHeight < _elm.scrollHeight) || 
         (_elm.clientWidth < _elm.scrollWidth)) {
         _hasScrollBar = true;
     }
     return _hasScrollBar;
 }

 function ab() {
     var a = $('td');
     $.each(a, function (i, data) {
         var check = data.HasScrollBar();
         if (check == true) {
             data.addClass('Overflow');
             data.attr('title', data.text());
         }
         data.attr('title', data.text());
         debugger;
     });

 };
 $('.Test').on('click', function () {

     ab();
 });
$.fn.HasScrollBar=函数(){
//注:clientHeight=支架高度
//scrollHeight=在此高度之前我们都有内容
var_elm=$(此)[0];
var _hasScrollBar=false;
如果(_elm.clientHeight<_elm.scrollHeight)|
(_elm.clientWidth<_elm.scrollWidth)){
_hasScrollBar=true;
}
返回(hasScrollBar);;
}
函数ab(){
var a=$('td');
$。每个(a,函数(i,数据){
var check=data.HasScrollBar();
如果(检查==true){
data.addClass(“溢出”);
data.attr('title',data.text());
}
data.attr('title',data.text());
调试器;
});
};
$('.Test')。在('click',函数(){
ab();
});

第二个参数是
$。each()
(在本例中是
data
)是一个DOM元素,而不是jQuery对象,因此它没有jQuery方法。首先需要将其包装到jQuery元素中:

 $.each(a, function (i, data) {
     var $data = $( data );
     var check = $data.HasScrollBar();
     if (check == true) {
         $data.addClass('Overflow');
         $data.attr('title', $data.text());
     }
     $data.attr('title', $data.text());
 });

$的第二个参数。each()
(在本例中为
数据
)是一个DOM元素,而不是jQuery对象,因此它没有jQuery方法。首先需要将其包装到jQuery元素中:

 $.each(a, function (i, data) {
     var $data = $( data );
     var check = $data.HasScrollBar();
     if (check == true) {
         $data.addClass('Overflow');
         $data.attr('title', $data.text());
     }
     $data.attr('title', $data.text());
 });

由于您不需要计数器,因此可以在集合上运行.each

也不需要在if的内部和外部添加标题

$('td').each(function () {
  var $this = $(this);
  $this.toggleClass('Overflow',$this.HasScrollBar());
  $this.attr('title', $this.text());
});

由于您不需要计数器,因此可以在集合上运行.each

也不需要在if的内部和外部添加标题

$('td').each(function () {
  var $this = $(this);
  $this.toggleClass('Overflow',$this.HasScrollBar());
  $this.attr('title', $this.text());
});

有滚动条
!=
HasScrollBar
这是什么意思?除非您使用
$('foo')['has scrollbar']
调用它,否则错误不太可能是“has no method'has scrollbar'”。重要的是你要准确地复制粘贴错误消息,否则人们会被转移。
有滚动条
!=
HasScrollBar
这是什么意思?除非您使用
$('foo')['has scrollbar']
调用它,否则错误不太可能是“has no method'has scrollbar'”。重要的是你要准确地复制粘贴错误消息,否则人们会被转移注意力$a、 each(function(){$var check=$(this).HasScrollBar();使用var a=$('td');$a.each(function(){$var check=$(this).HasScrollBar()是否可以解决这个问题;