Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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_Html - Fatal编程技术网

jQuery在提交时设置多个类的动画

jQuery在提交时设置多个类的动画,jquery,html,Jquery,Html,我有一组31个div,每个div都有一个数字类。我正在尝试使所有具有“今天日期”或“更早日期”类的div在单击“提交”按钮时都具有动画效果 <div class="image 1">SAMPLE TEXT</div> <div class="image 2">SAMPLE TEXT</div> <div class="image 3">SAMPLE TEXT</div> <div class="image 4">

我有一组31个div,每个div都有一个数字类。我正在尝试使所有具有“今天日期”或“更早日期”类的div在单击“提交”按钮时都具有动画效果

<div class="image 1">SAMPLE TEXT</div>
<div class="image 2">SAMPLE TEXT</div>
<div class="image 3">SAMPLE TEXT</div>
<div class="image 4">SAMPLE TEXT</div>
<form>
   <input class="previous" type="submit" value="View Previous" />
</form>
示例文本
示例文本
示例文本
示例文本
而这一点jQuery,但它远远不能工作,我无法为我的生活找出原因

$("form").submit(function() 
    {
    var number = $('div.image').attr("class").match(/\d+/),
        d = new Date(),
        day = d.getDate();

    if (number <= day){
        $('div.image').animate({"height":"0px", "width":"150px", "bottom":"75px"}, 500);
    }
    else {
    }
});
$(“表单”).submit(函数()
{
变量编号=$('div.image').attr(“类”).match(/\d+/),
d=新日期(),
day=d.getDate();

如果(数字第一个:您必须从函数表单提交返回false(不要重新加载页面)。然后


因为表单在动画开始运行之前已提交 您应该在动画之后添加
return false

那样

if (number <= day){

    $('div.image').animate({"height":"0px", "width":"150px", "bottom":"75px"}, 500);

    return false;
}

else {

}

if(number为什么不在div上使用自定义属性呢?试试这样的方法

HTML:

示例文本
示例文本
示例文本
示例文本
JavaScript:

$('div.image').each(function()
{
    var number = $(this).attr('number'),
        d = new Date(),
        day = d.getDate();

    if (number <= day){
        $(this).animate({"height":"0px", "width":"150px", "bottom":"75px"}, 500);
    }
});
$('div.image')。每个(函数()
{
var number=$(this.attr('number'),
d=新日期(),
day=d.getDate();

如果(数字)有什么不起作用?
if (number <= day){

    $('div.image').animate({"height":"0px", "width":"150px", "bottom":"75px"}, 500);

    return false;
}

else {

}
<div class="image" number="1">SAMPLE TEXT</div>
<div class="image" number="2">SAMPLE TEXT</div>
<div class="image" number="3">SAMPLE TEXT</div>
<div class="image" number="4">SAMPLE TEXT</div>
<form>
   <input class="previous" type="submit" value="View Previous" />
</form>
$('div.image').each(function()
{
    var number = $(this).attr('number'),
        d = new Date(),
        day = d.getDate();

    if (number <= day){
        $(this).animate({"height":"0px", "width":"150px", "bottom":"75px"}, 500);
    }
});