<select name="indication_subject[]">
<option value="" selected="selected">a </option>
<option> Accounting</option>
<option> Afrikaans</option>
<option> Applied Information and Communication Technology</option>
<option> Arabic</option>
<option> Art and Design</option>
<option> Biology</option>
<option> Business Studies</option>
</select>
<select name="indication_subject[]">
<option value="" selected="selected">a </option>
<option> Accounting</option>
<option> Afrikaans</option>
<option> Applied Information and Communication Technology</option>
<option> Arabic</option>
<option> Art and Design</option>
<option> Biology</option>
<option> Business Studies</option>
</select>
답변
난 당신이 요소를 선택하고 방법을 잘 모르겠어요이 양식에 두 번 같은 값을 선택에서 사용자를 방지하려는, 그래서 나는거야 간단하게 ID를 부여하십시오.
예 :http://jsfiddle.net/x4E5Q/1/
function preventDupes(select, index) {
var options = select.options,
len = options.length;
while(len--) {
options[ len ].disabled = false;
}
select.options[ index ].disabled = true;
if(index === select.selectedIndex) {
alert('You\'ve already selected the item "' + select.options[index].text + '".\n\nPlease choose another.');
this.selectedIndex = 0;
}
}
var select1 = select = document.getElementById('select1');
var select2 = select = document.getElementById('select2');
select1.onchange = function() {
preventDupes.call(this, select2, this.selectedIndex);
};
select2.onchange = function() {
preventDupes.call(this, select1, this.selectedIndex);
};
HTML은
<select id="select1" name="indication_subject[]">
<option value="" selected="selected">a </option>
<option> Accounting</option>
<option> Afrikaans</option>
<!-- ...and so on... -->
<select id="select2" name="indication_subject[]">
<option value="" selected="selected">a </option>
<option> Accounting</option>
<option> Afrikaans</option>
<!-- ...and so on... -->
편집 :는 .disabled
를 지원하지 않는 브라우저를 다루는 변경되었습니다. 신용은 @Zoidberg입니다.
IE 7 이전에서는 작동하지 않습니다. – Zoidberg
@Zoidberg : 예, 업데이트되었습니다. 그 언급에 대해 +1하십시오. – user113716
dw 아무런 문제가 없으므로 답변이 완전하다고 확신하고 싶습니다. 내 답변보다 훨씬 우아하고 아마도 허용 될 것입니다. :) – Zoidberg
궁극적으로 부동산을 구입할 수 있다면 라디오 버튼이나 체크 박스를 사용하여 최대 2 개의 체크 박스 만 선택할 수 있습니다. 나에게이 상황에서 드롭 다운이 작동하지 않는다.
그러나 부동산이없고 드롭 다운을 사용해야하는 경우 가장 좋은 방법은 첫 번째 드롭 다운에서 값을 선택하면됩니다. , 두 번째 드롭 다운에서 비활성화 또는 제거하거나 반대의 경우 (첫 번째 드롭 다운에서 값을 선택하는 경우). 제거하는 것과는 달리 비활성화하는 것이 좋습니다. 사용자에게 무엇이 진행되고 있는지가 분명해지기 때문입니다. 일찍
function updateSelect(changedSelect, selectId) {
var otherSelect = document.getElementById(selectId);
for (var i = 0; i < otherSelect.options.length; ++i) {
otherSelect.options[i].disabled = false;
}
if (changedSelect.selectedIndex == 0) {
return;
}
otherSelect.options[changedSelect.selectedIndex].disabled = true;
}
유일한 문제는
, IE 7로 이동하고
<select id="subject1" onchange="updateSelect(this,'subject2');" name="indication_subject[]">
<option value="" selected="selected">a </option>
<option value="1"> Accounting</option>
<option value="2"> Afrikaans</option>
<option value="3"> Applied Information and Communication Technology</option>
<option value="4"> Arabic</option>
<option value="5"> Art and Design</option>
<option value="6"> Biology</option>
<option value="7"> Business Studies</option>
</select>
<select id="subject2" name="indication_subject[]" onchange="updateSelect(this,'subject1');" >
<option value="" selected="selected">a </option>
<option value="1"> Accounting</option>
<option value="2"> Afrikaans</option>
<option value="3"> Applied Information and Communication Technology</option>
<option value="4"> Arabic</option>
<option value="5"> Art and Design</option>
<option value="6"> Biology</option>
<option value="7"> Business Studies</option>
</select>
그런 다음 JS는 장애인 지원하지 않습니다. 이 것이 거래 차단기 인 경우 다른 선택 항목에서 옵션을 제거한 다음 나중에 교체해야합니다. 이 문제는 전체 목록을 새로 고치지 않으면 옵션의 순서가 변경된다는 점만 다릅니다. 전체 목록을 새로 고치려면 옵션과 값을 변경하지 않는 배열 (모델과 비슷한)에 저장해야하며 변경 이벤트가 발생할 때 선택 항목을 업데이트하는 데 사용해야합니다.
선택합니다
자바 스크립트 1. 및 id="indication_subject2"
에 id="indication_subject1"
를 추가,이 시도 :
$('#indication_subject1').change(function(){
var indication_subject1 = $('#indication_subject1').val();
var indication_subject2 = $('#indication_subject2').val();
if (indication_subject1 == indication_subject1)
{
$('#indication_subject2').prop('selectedIndex',0);// val = "" selected, or you can add alert('Can't select same value!')
}
});
$('#indication_subject2').change(function(){
var indication_subject1 = $('#indication_subject1').val();
var indication_subject2 = $('#indication_subject2').val();
if (indication_subject2 == indication_subject1)
{
$('#indication_subject1').prop('selectedIndex',0);
}
});
- 1. 쿼리에서 고유 한 값을 선택할 수 없습니다.
- 2. 암호를 선택할 수 없습니다
- 3. 아이폰에서 선택할 수 없습니다 indexrow
- 4. 두 개의 ID를 사용하여 CSS에서 선택할 수 있습니까? # content.special #page
- 5. jquery로 양식을 선택할 수 없습니다
- 6. 동시에 두 개의 값을 던질 수 있습니까?
- 7. 두 개의 값을 URL에 삽입하십시오.
- 8. JQuery를 올바르게 선택할 수 없습니다.
- 9. UIImagePickerController 그림을 선택할 수 없습니다.
- 10. Safari에서 텍스트를 선택할 수 없습니다.
- 11. perl에서 두 개의 값을 추가해야합니다.
- 12. 나만의 토큰 값을 선택할 수 있습니까?
- 13. jquery 속성 선택기로 속성을 선택할 수 없습니다.
- 14. 테이블 셀 안의 uipickerviews를 선택할 수 없습니다.
- 15. 두 개의 키 값이 같은 경우, 두 개의 별도 해시 키가 같은 경우 교차점을 만듭니다. Ruby
- 16. FDT 코드 지원 : 옵션을 선택할 수 없습니다.
- 17. django에서 복수 필드를 선택할 수 없습니다 admin
- 18. 액티비티 생성시 예외 : 항목을 선택할 수 없습니다. 소계 마샬링 값을 사용할 수 없습니다.
- 19. 목록 상자 항목을 선택할 수 없습니다.
- 20. Extjs 콤보 상자가 항목을 선택할 수 없습니다
- 21. 드래그 앤 드롭과 jQuery로 위치를 감지하고 싶습니까?
- 22. IE의 입력 상자에서 텍스트를 선택할 수 없습니다
- 23. 열의 값을 두 개의 다른 열로 나누십시오.
- 24. mouseOver 명령에 두 개의 값을 추가 할 수 있습니까?
- 25. 안드로이드 커서로 데이터베이스에서 열을 선택할 수 없습니다
- 26. jQuery에서 두 클래스가있는 요소를 선택할 수 있습니까
- 27. 두 개의 Microsoft Access 데이터베이스를 하나의 양식으로 결합하여 두 가지 중에서 선택할 수 있습니다.
- 28. Jquery에서 두 개의 변수를 추가 할 수 없습니다.
- 29. XmlElement에서 루트 노드를 선택할 수 없습니다.
- 30. 코드가 올바르더라도 데이터베이스 테이블을 선택할 수 없습니다.
당신이 jQuery를 사용할 수 또는 일반 자바 스크립트를해야합니까? 그리고 당신은 동일한 옵션 **뿐만 아니라 ** 같은 이름을 가진 두 개의 선택을 가지고 있습니까? – ThiefMaster
두 개의 선택 상자 대신''indication_subject [accounting]'',''indication_subject [afrikaans] ''등의 체크 박스를 사용하는 것은 어떻습니까? 이렇게하면 사용자가 다양한 수의 고유 항목을 선택할 수 있습니다. 물론 사용자가 * 정확하게 * 두 항목을 선택하기를 원하면이 방법은 도움이되지 않습니다. – redShadow
@ThiefMaster 둘 이상의 양식 항목에 동일한 이름을 사용하면 요청 URL에'? myname = val1 & myname = val2 & myname = val3'이 표시되며, 일반적으로 '배열 (val1, val2, val3)'으로 변환됩니다. – redShadow