매우 쉽게 롤 수 있습니다. 과 같이 마크 업으로 시작합니다 활성화 자바 스크립트, 사용자가 위의를 얻을 것이다
<fieldset>
<input type="radio" name="weather" value="sunny" />
<input type="radio" name="weather" value="cloudy" />
<input type="radio" name="weather" value="rainy" />
<input type="radio" name="weather" value="class-3-kill-storm" />
</fieldset>
없이 (사람들이 클릭하고 있었는지 알고, 그래서 당신은 아마 레이블 요소를 추가 할 것). 그들 모두를 통해 다음 루프는 당신이 당신의 아이콘에 대한 필요가있을 <a>
요소를 생성 : IE 제대로 :hover
CSS의 pseudoclass을 존중하기 때문에 내가 <a>
을 사용하고
$('input[name=weather]').each(function() {
var radio = $(this);
radio.css({display: 'none'});
var icon = $('<a class="icon ' + this.value + '"></a>');
icon.click(function(e) {
// stop default link click behaviour
e.preventDefault();
// unmark any previously selected image and mark clicked selected
icon.siblings('.icon').removeClass('selected');
icon.addClass('selected');
// set associated radio button's value
radio.attr('checked', 'true');
});
$(this).parent().append(icon);
});
이유입니다. 또한 그 메모에서 CSS 스프린트를 사용하므로 그레이 버전과 풀 컬러 이미지를 40px 높이의 이미지로 결합 할 수 있습니다. 당신은 버전이 배경 색상 in action here를 사용하여 볼 수 있습니다
a.icon {
float: left;
/* width and height of your weather icons */
width: 20px;
height: 20px;
background-repeat: no-repeat;
background-position: 0 0;
}
a.selected,
a:hover.icon {
background-position: 0 -20px;
}
.sunny{
background-image: url(sunny.png);
}
.rainy {
background-image: url(rainy.png);
}
/* remaining weather styles */
:
<a>
의 CSS처럼 보일 것입니다.
출처
2010-08-23 16:15:02
Pat
이렇게 좋네요. 내가 다시 한번 내보기를 컴파일 해 드리겠습니다. http://stackoverflow.com/questions/3550244/asp-net-mvc-strongly-typed-view-compilation-error –
하, 나에게 모든 일이 일어난다. 시간 - 프론트 엔드에서 작업하고 백엔드에서 나를 싸우기 시작합니다. – Pat
이제 마침내 그것을 보았습니다. 나는 다시 돌아 왔습니다. http://jsfiddle.net 사이트가 환상적입니다 BTW! –