jQuery在提交时设置多个类的动画
我有一组31个div,每个div都有一个数字类。我正在尝试使所有具有“今天日期”或“更早日期”类的div在单击“提交”按钮时都具有动画效果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">
<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);
}
});