코딩의 초보자이므로이 코드를 완전히 이해하지 못했습니다.
내가 달성하고자하는 것은 다중 드롭 다운 메뉴를 넣고 싶다는 것입니다.
내 코드의 문제점은 특정 드롭 다운 메뉴에서만 값을 허용한다는 점입니다.다른 드롭 다운 메뉴의 값 사용
내 코드는 사용자가 이전 드롭 다운 메뉴에서 선택한 항목에 따라 지역, 국가 및 주를 선택하는 데 도움이됩니다. 이 코드는 내가 달성하고자하는 것과 유사하기 때문에이 코드를 사용하고 있습니다.
제가 직면 한 문제는 데이터를 사용해야하는 약 8 개의 드롭 다운 메뉴가 있다는 것입니다. 8 개의 지역 드롭 다운, 8 개의 국가 드롭 다운 및 8 개의 국가 드롭 다운이 있습니다. 모두 같은 페이지에 있습니다. 코드를 8 개 넣으면 코드가 작동을 멈 춥니 다. 내가 도대체 뭘 잘못하고있는 겁니까?
누군가 저를 도와 줄 수 있습니까? 이 코드입니다 :
<form>
Region» <select onchange="set_country(this,country,city_state)" size="1" name="region">
<option value="" selected="selected">SELECT NOTE</option>
<option value=""></option>
<script type="text/javascript">
setRegions(this);
</script>
</select>
Country» <select name="country" size="1" disabled="disabled" onchange="set_city_state(this,city_state)"></select>
City/State» <select name="city_state" size="1" disabled="disabled" onchange="print_city_state(country,this)"></select>
<script>
////////////////////////////////////////////////////////////////////////////
// city_state.js ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
var countries = Object();
countries['C'] = '|C|Cm|';
countries['D'] = '|D|Dm|';
////////////////////////////////////////////////////////////////////////////
var city_states = Object();
//C
city_states['C'] = '|032010|335553|';
city_states['Cm'] = '|335543|';
city_states['D'] = '|000232|557775';
city_states['Dm'] = '|000231|557765';
////////////////////////////////////// ///////////////////////////////// /////////// /////////////////////////////////////////////////////////////////// ///////////////
function setRegions()
{
for (region in countries)
document.write('<option value="' + region + '">' + region + '</option>');
}
function set_country(oRegionSel, oCountrySel, oCity_StateSel)
{
var countryArr;
oCountrySel.length = 0;
oCity_StateSel.length = 0;
var region = oRegionSel.options[oRegionSel.selectedIndex].text;
if (countries[region])
{
oCountrySel.disabled = false;
oCity_StateSel.disabled = true;
oCountrySel.options[0] = new Option('SELECT TYPE','');
countryArr = countries[region].split('|');
for (var i = 0; i < countryArr.length; i++)
oCountrySel.options[i + 1] = new Option(countryArr[i], countryArr[i]);
document.getElementById('txtregion').innerHTML = region;
document.getElementById('txtplacename').innerHTML = '';
}
else oCountrySel.disabled = true;
}
function set_city_state(oCountrySel, oCity_StateSel)
{
var city_stateArr;
oCity_StateSel.length = 0;
var country = oCountrySel.options[oCountrySel.selectedIndex].text;
if (city_states[country])
{
oCity_StateSel.disabled = false;
oCity_StateSel.options[0] = new Option('SELECT TAB','');
city_stateArr = city_states[country].split('|');
for (var i = 0; i < city_stateArr.length; i++)
oCity_StateSel.options[i+1] = new Option(city_stateArr[i],city_stateArr[i]);
document.getElementById('txtplacename').innerHTML = country;
}
else oCity_StateSel.disabled = true;
}
function print_city_state(oCountrySel, oCity_StateSel)
{
var country = oCountrySel.options[oCountrySel.selectedIndex].text;
var city_state = oCity_StateSel.options[oCity_StateSel.selectedIndex].text;
if (city_state && city_states[country].indexOf(city_state) != -1)
document.getElementById('txtplacename').innerHTML = city_state + ', ' + country;
else document.getElementById('txtplacename').innerHTML = country;
}
</script>
내가 특정 코드를 필요가 있다고 생각하기 때문에 자바 스크립트 섹션에 자바 스크립트 코드를 붙여하지 않은 http://jsfiddle.net/HzJ9J/1/ 에서 업데이트 된 코드를 확인하시기 바랍니다 올바른 장소에서 뛰기. 확실하지 않은 경우 자바 스크립트 섹션으로 이동해야합니다.
안녕하세요 밥, 언급하신대로 시도했습니다. 다른 3 개의 드롭 다운 메뉴를 추가 할 수 있지만 첫 번째 드롭 다운 메뉴 만 작동합니다. 나머지는 작동하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? Chrome에서 개발자 도구를 사용하는 방법을 알지 못합니다. ( – Sudhin
코드가 질문에 게시 한 코드와 다른 것 같기 때문에 현재 코드를 jsfiddle.net에 넣고 편집 할 수 있습니다. 귀하의 질문에 대한 포인터를 제공하십시오. JavaScript로 개발하려는 경우 개발자 도구를 배워야 할 것입니다. –
안녕하세요, Bob, jsfiddle.net에 코드를 넣었습니다. 확인해주십시오. 그것과 실수를 말해? 고마워요! – Sudhin