Я пишу кнопку «Подобная кнопку» с jQuery, но у меня есть некоторые проблемы с условными.if (total_likes > 0) {
$hide = 'block';
} $hide = 'none';
$photos_box .= '
' . $like . '
//the counter
' . $total_likes . '
// the text
[*]
' . $text . '
< /code>
Скрипт jQuery: < /p>
$('.like_button').click(function() {
var total_likes = $('.tl'+this.id).val();
total_likes = parseInt(total_likes);
var status = '';
if ($(this).html() == 'Like') {
status = 'like';
$(this).html('Unlike');
$(this).attr('title', 'Unlike this');
$('.mod'+this.id).html(total_likes+1);
if (total_likes == 0) {
$('#counter').slideToggle('fast');
$('.text_color').html('Like this.');
} else if (total_likes == 1) {
$('.text_color').html('You and other like this.');
} else if (total_likes > 2) {
var tl = total_likes+1;
$('.text_color').html('You and '+tl+' others like this.');
}
} else if ($(this).html() == 'Unlike') {
status = 'unlike';
$(this).html('Like');
$(this).attr('title', 'Like this');
$('.mod'+this.id).html(total_likes-1);
if (total_likes == 0 || total_likes == 1) {
$('#counter').slideToggle('fast');
} else if (total_likes == 2) {
$('.text_color').html('1 person like this.');
} else if (total_likes > 2) {
var tl = total_likes-1;
$('.text_color').html(''+tl+' people like this.');
}
}
var data = {
img_id : this.id,
sta : status
};
$.ajax({
type : 'POST',
url : '/includes/like.php',
data : data
}).done(function(result) {
console.log(result);
});
});
< /code>
Работа с jQuery и изменениями в реальном времени -это беспорядок ... Я не уверен, что условные условия правы, чтобы делать то, что ему нужно.>
Подробнее здесь: https://stackoverflow.com/questions/269 ... conditions
Нажмите не цеплять текст/числа правильно с условиями, если условия ⇐ Jquery
Программирование на jquery
-
Anonymous
1754473914
Anonymous
Я пишу кнопку «Подобная кнопку» с jQuery, но у меня есть некоторые проблемы с условными.if (total_likes > 0) {
$hide = 'block';
} $hide = 'none';
$photos_box .= '
' . $like . '
//the counter
' . $total_likes . '
// the text
[*]
' . $text . '
< /code>
Скрипт jQuery: < /p>
$('.like_button').click(function() {
var total_likes = $('.tl'+this.id).val();
total_likes = parseInt(total_likes);
var status = '';
if ($(this).html() == 'Like') {
status = 'like';
$(this).html('Unlike');
$(this).attr('title', 'Unlike this');
$('.mod'+this.id).html(total_likes+1);
if (total_likes == 0) {
$('#counter').slideToggle('fast');
$('.text_color').html('Like this.');
} else if (total_likes == 1) {
$('.text_color').html('You and other like this.');
} else if (total_likes > 2) {
var tl = total_likes+1;
$('.text_color').html('You and '+tl+' others like this.');
}
} else if ($(this).html() == 'Unlike') {
status = 'unlike';
$(this).html('Like');
$(this).attr('title', 'Like this');
$('.mod'+this.id).html(total_likes-1);
if (total_likes == 0 || total_likes == 1) {
$('#counter').slideToggle('fast');
} else if (total_likes == 2) {
$('.text_color').html('1 person like this.');
} else if (total_likes > 2) {
var tl = total_likes-1;
$('.text_color').html(''+tl+' people like this.');
}
}
var data = {
img_id : this.id,
sta : status
};
$.ajax({
type : 'POST',
url : '/includes/like.php',
data : data
}).done(function(result) {
console.log(result);
});
});
< /code>
Работа с jQuery и изменениями в реальном времени -это беспорядок ... Я не уверен, что условные условия правы, чтобы делать то, что ему нужно.>
Подробнее здесь: [url]https://stackoverflow.com/questions/26937481/click-not-chaining-text-numbers-correctly-with-if-conditions[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия