Jquery 如果没有更多图片,请禁用(nxt/prv)按钮
我已经问过同样的问题了 在那之后,我想出了以下代码: css jqueryJquery 如果没有更多图片,请禁用(nxt/prv)按钮,jquery,html,css,slider,Jquery,Html,Css,Slider,我已经问过同样的问题了 在那之后,我想出了以下代码: css jquery var size = $("#content table").find('tr').first().find('td').size(); var position = 1; $("#left").click( function() { if(position < (size / 2)) { $('#right').removeAttr('disabled'); $
var size = $("#content table").find('tr').first().find('td').size();
var position = 1;
$("#left").click( function() {
if(position < (size / 2)) {
$('#right').removeAttr('disabled');
$("#content").animate({"right": "+=198px"}, "fast");
position ++;
}else{
$('#left').attr("disabled", "true");
}
});
$("#right").click( function() {
if( position > 1) {
$('#left').removeAttr('disabled');
$("#content").animate({"right": "-=198px"}, "fast");
position --;
}else{
$('#right').attr("disabled", "true");
}
});
var size=$(“#内容表”).find('tr').first().find('td').size();
var位置=1;
$(“#左”)。单击(函数(){
如果(位置<(尺寸/2)){
$('右').removeAttr('禁用');
$(“#content”).animate({“right”:“+=198px”},“fast”);
位置++;
}否则{
$(“#左”).attr(“禁用”、“真”);
}
});
$(“#右”)。单击(函数(){
如果(位置>1){
$('左').removeAttr('禁用');
$(“#content”).animate({“right”:“-=198px”},“fast”);
位置--;
}否则{
$('#right').attr(“disabled”、“true”);
}
});
html
说明1
说明2
说明3
说明4
说明5
描述6
这对我来说没问题,但请看现场演示
您可以看到,nxt和prv按钮已禁用,但不是在pics设置完成后立即禁用!你应该再点击一次按钮来禁用它
如何使这些按钮立即禁用
谢谢你这就够了
$("#left").click( function() {
if(position < (size / 2)) {
$('#right').removeAttr('disabled');
$("#content").animate({"right": "+=198px"}, "fast");
position ++;
}if(position >= (size / 2)){
$('#left').attr("disabled", "true");
}
});
$("#right").click( function() {
if( position > 1) {
$('#left').removeAttr('disabled');
$("#content").animate({"right": "-=198px"}, "fast");
position --;
}if(position == 1){
$('#right').attr("disabled", "true");
}
});
$(“#左”)。单击(函数(){
如果(位置<(尺寸/2)){
$('右').removeAttr('禁用');
$(“#content”).animate({“right”:“+=198px”},“fast”);
位置++;
}如果(位置>=(尺寸/2)){
$(“#左”).attr(“禁用”、“真”);
}
});
$(“#右”)。单击(函数(){
如果(位置>1){
$('左').removeAttr('禁用');
$(“#content”).animate({“right”:“-=198px”},“fast”);
位置--;
}如果(位置==1){
$('#right').attr(“disabled”、“true”);
}
});
你真的应该反转动画的方向,现在的方式很混乱
$("#left").click(function() {
$('#right').removeAttr('disabled');
$("#content").animate({
"right": "+=198px"
}, "fast");
position++;
if (position == (size / 2)) {
$('#left').attr("disabled", "true");
}
});
$("#right").click(function() {
$('#left').removeAttr('disabled');
$("#content").animate({
"right": "-=198px"
}, "fast");
position--;
if (position == 1) {
$('#right').attr("disabled", "true");
}
});
谢谢你现在的工作,但是我忘了一件事,我怎么能从一开始就禁用左键呢?谢谢你的帮助,谢谢你的关心
$("#left").click( function() {
if(position < (size / 2)) {
$('#right').removeAttr('disabled');
$("#content").animate({"right": "+=198px"}, "fast");
position ++;
}if(position >= (size / 2)){
$('#left').attr("disabled", "true");
}
});
$("#right").click( function() {
if( position > 1) {
$('#left').removeAttr('disabled');
$("#content").animate({"right": "-=198px"}, "fast");
position --;
}if(position == 1){
$('#right').attr("disabled", "true");
}
});
$("#left").click(function() {
$('#right').removeAttr('disabled');
$("#content").animate({
"right": "+=198px"
}, "fast");
position++;
if (position == (size / 2)) {
$('#left').attr("disabled", "true");
}
});
$("#right").click(function() {
$('#left').removeAttr('disabled');
$("#content").animate({
"right": "-=198px"
}, "fast");
position--;
if (position == 1) {
$('#right').attr("disabled", "true");
}
});