내 함수는 URL에 해시가 있는지 확인하고 값을 반환하고 해당 값을 사용하여 ID로 이미지를 찾고 클래스 이름을 적용합니다. 내 콘솔에 오류가 표시되지 않지만 예상 된 결과가 표시되지 않습니다. 대신, id=image
jQuery가 해시를 검색하여 ID로 적용합니다.
에 .z
클래스의 모든를 쓰고 반환 hash
값으로 .z
클래스를 필터링
는 그 값을 필터링하고 ID로 사용하는 더 좋은 방법이 있나요? 감사!
자바 스크립트 :
(function($){
$.brantley = function(callback) {
var $doc = $(document),
$win = $(window),
$z, $load, $footer, $header, $status, $container;
$doc.ready(function() {
$z = $('.z');
$load = $('#load');
$footer = $('footer');
$header = $('header');
$status = $('#status');
$container = $('#container');
var hash = gethash();
if(hash) {
$('#' + hash + '.z').addClass('active');
} else {
$('.z:first').addClass('active');
}
bromance();
});
$win.load(function() {
bromance();
$load.fadeOut('fast', function() {
$('.active').fadeIn('slow');
$status.fadeIn('slow');
$footer.fadeIn('slow');
});
});
$win.resize(function() {
bromance();
});
function gethash() {
var hash=window.location.hash;
hash=hash.replace(/#/,'');
return hash;
}
function updateNumber(type) {
window.location = window.location.pathname + "#" + type;
}
};
})(jQuery);
어,'var image = hash;'는 아무 것도하지 않고 해시 객체는 사용되지 않습니다. 너 뭐하려고? – tjameson
구문 오류가 있습니다 :'$ container = $ ('# container'), - 쉼표는 세미콜론이어야합니다. –
'hash' 변수에'$'가 없습니다. 이 해시 변수는 이제 전역 변수이며 로컬 변수가 아닙니다. 상단의'$ hash '변수는 실제로 사용되지 않습니다. – tjameson