Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   ПОМОГИТЕ! У меня не работает else уже вcё перепробывал. if работает (https://javascript.ru/forum/jquery/69060-pomogite-u-menya-ne-rabotaet-else-uzhe-vcjo-pereprobyval-if-rabotaet.html)

Jandes 27.05.2017 16:05

ПОМОГИТЕ! У меня не работает else уже вcё перепробывал. if работает
 
$(function(){ 
$('#div_for_img img').each(function(){ 
$(this).click(function(){ 
var a=$(this).attr('width'); 
var b=parseInt(a); 
b=a/2; 
w=0; 
if (w=1){ 
$(this).attr('width', a); 
$(this).attr('height', a); 
w=0; 
}else{ 
$(this).attr('width', b); 
$(this).attr('height', b); 
w=1; 
}; 
})}); 
}) 
;

j0hnik 27.05.2017 16:12

значит условие всегда выполняется!
<head>
	<meta charset="utf-8">
</head>
<body>
	<script>
	if(1>0.5) { alert("верно!");}
	else { alert("не верно!");}
  </script>
</body>

j0hnik 27.05.2017 16:15

не
if (w=1){

а
if (w===1){

или
if (w==1){

Stasjs 27.05.2017 16:21

спосибо

Stasjs 27.05.2017 16:21

но ето не всьо

Stasjs 27.05.2017 16:22

теперь работает только else

Stasjs 27.05.2017 16:26

$(function(){
$('#div_for_img img').each(function(){
$(this).click(function(){
var a=$(this).attr('width');
var b=parseInt(a);
b=a/2;
w=1;
if (w==1){
$(this).attr('width', a);
$(this).attr('height', a);
w=0;
}else if(w==0){
$(this).attr('width', b);
$(this).attr('height', b);
w=1;
}
})});
})
;

так тоже не работает

j0hnik 27.05.2017 16:34

напишите что конкретно должно происходить не в функции а вообще
Типа: кликаем на картинку и она ... ???

рони 27.05.2017 16:36

Jandes,
$(function() {
    $("#div_for_img img").each(function() {
        var a = $(this).attr("width");
        var b = parseInt(a);
        b = a / 2;
        var w = 0;
        $(this).click(function() {
            if (w == 1) {
                $(this).attr("width", a);
                $(this).attr("height", a);
                w = 0
            } else {
                $(this).attr("width", b);
                $(this).attr("height", b);
                w = 1
            }
        })
    })
});

Stasjs 27.05.2017 16:38

Папробуй так:
$(function(){var w=0;
$('#div_for_img img').each(function(){
$(this).click(function(){
var a=$(this).attr('width');
var b=parseInt(a);
b=a/2;

if (w==1){
$(this).attr('width', a*2);
$(this).attr('height', a*2);
w=0;
}else{
$(this).attr('width', b);
$(this).attr('height', b);
w=1;
};
})});
})
;


Часовой пояс GMT +3, время: 23:47.