이 함수를 만들었으므로 논리 흐름을 정렬하는 데 도움이 필요합니다. 그것은 어느 정도 작동하며 버그를 제거하는 데 도움이됩니다.jQuery는 체크 박스 클릭을 감지하는 기능을 내 논리로 사용합니다.
내 HTML : 여기
<span style="float: left;"><input type="checkbox" id="top" name="position" value="top" /> Top </span>
<span style="float: left;"><input type="checkbox" id="bottom" name="position" value="bottom" /> Bottom </span>
<span style="float: left;"><input type="checkbox" id="left" name="position" value="left" /> Left </span>
<span style="float: left;"><input type="checkbox" id="center" name="position" value="center" /> Center </span>
<span style="float: left;"><input type="checkbox" id="right" name="position" value="right" /> Right</span>
그리고 내 jQuery를 기능 : 여기
/// Bind Position value to 'CSS : BackgroundPosition' ///
var $positions;
function bgpos(){
var pos = $positions.map(function() {
if($('#top').attr('checked') == true)
$('#bottom').attr('disabled', true);
else
$('#bottom').attr('disabled', false);
if($('#bottom').attr('checked') == true)
$('#top').attr('disabled', true);
else
$('#top').attr('disabled', false);
if($('#left').attr('checked') == true){
$('#right').attr('disabled', true);
$('#center').attr('disabled', true);
}else{
$('#right').attr('disabled', false);
$('#center').attr('disabled', false);
}
if($('#right').attr('checked') == true){
$('#left').attr('disabled', true);
$('#center').attr('disabled', true);
}else{
$('#left').attr('disabled', false);
$('#center').attr('disabled', false);
}
if(this.checked) return this.id;
}).get().join(' ');
//$('#queue').html(pos);
$('#topHeader').css({'backgroundPosition' : pos});
}
$(function() {
$positions = $("form#frm_look_and_feel input[name='position']").change(bgpos);
});
그리고 누군가가 관심이 있다면 내 jsFiddle입니다 :
http://jsfiddle.net/s2xi/nWT5J/2/
,'Top'을 클릭하면 'Bottom'이 비활성화되지 않지만 'Bottom'을 클릭하면 'Top'이 비활성화되고 'Left'를 클릭하면 같은 문제가 발생합니다. 내 '센터'는 비활성화되지 않지만 '오른쪽'을 클릭하면 '왼쪽'과 '센터'가 비활성화되는 것처럼 비활성화됩니다.
O.O 가끔 JavaScript가있는 초보자가되어 새로운 것을 가르쳐 줄 때가 있습니다. 고맙습니다. Nick – Eli
@ s2xi - welcome :) –
흠, 아마 라디오가 작동 할 수 있습니다. 나는이 옵션들 모두로 혼란스러워하지 않고 사용자가 백 그라운드 이미지를 배치하는데 사용할 수있는 옵션을 어떻게 식별 할 수 있었는지를 조사하고 있었다. – Eli