Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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
Javascript 如何在jquery代码中使用它_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何在jquery代码中使用它

Javascript 如何在jquery代码中使用它,javascript,jquery,html,Javascript,Jquery,Html,我在jquery中有如下代码: if($('div').width()>150){ $('#check').css('overflow-x', 'scroll'); $('#check').css('overflow-y', 'hidden'); } 我试图通过使用'this'关键字使这段代码更加具体,这样css属性将仅应用于特定的div 谁能告诉我做错了什么,因为“this”关键字在这种情况下不起作用 您应该从jquery中每个 $.each($('div'

我在jquery中有如下代码:

if($('div').width()>150){

    $('#check').css('overflow-x', 'scroll');  
    $('#check').css('overflow-y', 'hidden'); 

}
我试图通过使用'this'关键字使这段代码更加具体,这样css属性将仅应用于特定的div


谁能告诉我做错了什么,因为“this”关键字在这种情况下不起作用

您应该从jquery中
每个

$.each($('div'),function(){
    if($(this).width()>150){
        $(this).css('overflow-x', 'scroll');     
        $(this).css('overflow-y', 'hidden'); 
    }
})

您应该从jquery中
每个

$.each($('div'),function(){
    if($(this).width()>150){
        $(this).css('overflow-x', 'scroll');     
        $(this).css('overflow-y', 'hidden'); 
    }
})

您应该从jquery中
每个

$.each($('div'),function(){
    if($(this).width()>150){
        $(this).css('overflow-x', 'scroll');     
        $(this).css('overflow-y', 'hidden'); 
    }
})

您应该从jquery中
每个

$.each($('div'),function(){
    if($(this).width()>150){
        $(this).css('overflow-x', 'scroll');     
        $(this).css('overflow-y', 'hidden'); 
    }
})
你可以用它来做这个

$('div').filter(function () {
    return $(this).width() > 150;
}).css({
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
演示:

您可以使用

$('div').filter(function () {
    return $(this).width() > 150;
}).css({
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
演示:

您可以使用

$('div').filter(function () {
    return $(this).width() > 150;
}).css({
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
演示:

您可以使用

$('div').filter(function () {
    return $(this).width() > 150;
}).css({
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
演示:


这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本不会溢出。
$(“.scroll”).each(函数(){
如果($(this).width()>150){
$(this.css('overflow-x','scroll');
$(this.css('overflow-y','hidden');
}
});

这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本不会溢出。
$(“.scroll”).each(函数(){
如果($(this).width()>150){
$(this.css('overflow-x','scroll');
$(this.css('overflow-y','hidden');
}
});

这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本不会溢出。
$(“.scroll”).each(函数(){
如果($(this).width()>150){
$(this.css('overflow-x','scroll');
$(this.css('overflow-y','hidden');
}
});

这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本将溢出。
这将是一个测试,其中文本不会溢出。
$(“.scroll”).each(函数(){
如果($(this).width()>150){
$(this.css('overflow-x','scroll');
$(this.css('overflow-y','hidden');
}
});

您需要对所有
div
元素执行
width
检查。为此,您可以使用
过滤器
获取宽度满足要求的元素,然后在这些元素上设置CSS:

$('div').filter(function() {
    return $(this).width() > 150;
}).css({ 
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
请注意,将类应用于元素比直接更改CSS更好,因为这样可以更好地分离关注点:

$('div').filter(function() {
    return $(this).width() > 150;
}).addClass('horizontal-scroll');
。水平滚动{
溢出-x:滚动;
溢出y:隐藏;
}

您需要对所有
div
元素执行
width
检查。为此,您可以使用
过滤器
获取宽度满足要求的元素,然后在这些元素上设置CSS:

$('div').filter(function() {
    return $(this).width() > 150;
}).css({ 
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
请注意,将类应用于元素比直接更改CSS更好,因为这样可以更好地分离关注点:

$('div').filter(function() {
    return $(this).width() > 150;
}).addClass('horizontal-scroll');
。水平滚动{
溢出-x:滚动;
溢出y:隐藏;
}

您需要对所有
div
元素执行
width
检查。为此,您可以使用
过滤器
获取宽度满足要求的元素,然后在这些元素上设置CSS:

$('div').filter(function() {
    return $(this).width() > 150;
}).css({ 
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
请注意,将类应用于元素比直接更改CSS更好,因为这样可以更好地分离关注点:

$('div').filter(function() {
    return $(this).width() > 150;
}).addClass('horizontal-scroll');
。水平滚动{
溢出-x:滚动;
溢出y:隐藏;
}

您需要对所有
div
元素执行
width
检查。为此,您可以使用
过滤器
获取宽度满足要求的元素,然后在这些元素上设置CSS:

$('div').filter(function() {
    return $(this).width() > 150;
}).css({ 
    'overflow-x': 'scroll',
    'overflow-y': 'hidden'
});
请注意,将类应用于元素比直接更改CSS更好,因为这样可以更好地分离关注点:

$('div').filter(function() {
    return $(this).width() > 150;
}).addClass('horizontal-scroll');
。水平滚动{
溢出-x:滚动;
溢出y:隐藏;
}
试试看

试一试

试一试

试一试


我的版本带有“this”,希望能有所帮助

$('div').each(function(){
    if ($(this).width() > 150) {
       $(this).css('overflow-x', 'scroll');     
       $(this).css('overflow-y', 'hidden'); 
    }
}); 

我的版本带有“this”,希望对您有所帮助

$('div').each(function(){
    if ($(this).width() > 150) {
       $(this).css('overflow-x', 'scroll');     
       $(this).css('overflow-y', 'hidden'); 
    }
}); 

我的版本带有“this”,希望对您有所帮助

$('div').each(function(){
    if ($(this).width() > 150) {
       $(this).css('overflow-x', 'scroll');     
       $(this).css('overflow-y', 'hidden'); 
    }
}); 

我的版本带有“this”,希望对您有所帮助

$('div').each(function(){
    if ($(this).width() > 150) {
       $(this).css('overflow-x', 'scroll');     
       $(this).css('overflow-y', 'hidden'); 
    }
}); 

需要一个函数,该函数实际上将
的值设置为某个值,它不能随机使用,也不能被期望神奇地成为您想要的值。您是否意识到
$('div')
返回一个元素数组?好的,现在我知道了,但是如果我想使用$('div')返回的数组,我该怎么做呢?
这个
需要一个函数来实际设置
这个
的值,它不能被随机使用,也不能被期望神奇地变成你想要的样子。你意识到
$('div')
返回一个元素数组吗?好的,现在我知道了,但是如果我想使用$('div')返回的数组,我该怎么做呢?
这个
需要一个函数来实际设置
这个
的值,它不能被随机使用,也不能被期望神奇地变成你想要的样子