0
JS ans jQuery로 시작하고 있으며 현재 작업중인 Bootstrap 3 버튼의 코드를 개선하려고 노력해 왔습니다.jQuery 버튼 용 코드 개선
두 개의 내부 스팬이 있습니다. 하나는 텍스트와 하나는 쉐브론 글꼴 아이콘이 있습니다.
학습을 위해서 코드를 최적화 할 수있는 방법이 있는지 궁금합니다.
다음은 제 작업 코드입니다.
$('.btn-imgs').click(function(){
$('.thumbnail img').toggle();
//variables
var icono = $(this).children('.glyphicon');
var $text = $(this).children('.btn-imgs-toggle');
//cambia texto del boton
$text.toggleClass('mostrar');
//si el texto y el icono coinciden con un tipo cambialos al otro
if($text.hasClass('mostrar') && $(icono).is('.glyphicon-chevron-up')){
$text.text('Mostrar imágenes');
$(icono).removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
}
else {
$text.text('Ocultar imágenes');
$(icono).removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
}
});
덕분에 여기에 대한 입력에 대한 많은 다음 HTML 지금
<button type="button" class="btn btn-default btn-lg btn-imgs">
<span class="btn-imgs-toggle">Ocultar Imágenes </span>
<span class="glyphicon glyphicon-chevron-up"></span>
</button>
JQuery와
첫째. 나는 다른 게시 된 질문을 통해 검색을 많이 배우는 중이 었어.
, 당신은 http://codereview.stackexchange.com –
감사를 고려해 볼 수 있습니다! 그것에 대해 몰랐어! –