2016-11-16 4 views
0

양식 필드, 입력란, 드롭 다운 목록 및 확인란이 3 개 있습니다. 첫 번째 항목으로 드롭 다운 목록을 재설정하고 재설정을 클릭하면 선택을 취소하고 싶습니다. 이 코드를 시도했지만 드롭 다운 목록이 아닌 텍스트 상자 만 다시 설정합니다. 확인란을 다시 설정해야하는 경우도 있습니다.Javascript 재설정 드롭 다운 목록 및 확인란

참고 : 드롭 다운 목록 유형은 모델에 정의되어 있습니다.

<input type="text" name="a" class="input-medium w1" data-bind="value: value" /> 

<label class="control-label" for="category" id="ProductType">Type:&nbsp; @Html.EditorFor(m => m.Type)</label> 

<label class="control-label">Included Discontinued:@Html.CheckBox("searchDate")</label> 


    var dropDown = document.getElementById("ProductType"); 
     dropDown.selectedIndex = 0; 

    var elements = document.getElementsByTagName("input"); 
    for (var ii = 0; ii < elements.length; ii++) { 
     if (elements[ii].type == "text") { 
      elements[ii].value = ""; 
     }  
    } 
+0

'# ProductType'는 레이블이 아닌 드롭처럼 보인다? – adeneo

+0

이것은 드롭 다운 목록입니다. [[DropdownList ("ProductType")] public string Type {get; 세트; } –

답변

0

의 선택을 취소 확인란 예를

<!DOCTYPE html> 
<html> 
<body> 

<form> 
    What color do you prefer?<br> 
    <input type="radio" name="colors" id="red">Red<br> 
    <input type="radio" name="colors" id="blue">Blue 
</form> 

<button onclick="check()">Check "Red"</button> 
<button onclick="uncheck()">Uncheck "Red"</button> 

<script> 
function check() { 
    document.getElementById("red").checked = true; 
} 
function uncheck() { 
    document.getElementById("red").checked = false; 
} 
</script> 

</body> 
</html> 

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_radio_checked2

를 들어

document.getElementById("ID").checked = false; 

사용하십시오 목록 사용 드롭 다운 들어

예를 들어
document.getElementById("orange").selected = "true"; 

<!DOCTYPE html> 
<html> 
<body> 

<form> 
Select your favorite fruit: 
<select> 
    <option id="apple">Apple</option> 
    <option id="orange">Orange</option> 
    <option id="pineapple" selected>Pineapple</option> // Pre-selected 
    <option id="banana">Banana</option> 
</select> 
</form> 

<p>Click the button to change the selected option in the dropdown list to "orange" instead of "pinapple".</p> 

<button onclick="myFunction()">Try it</button> 

<script> 
function myFunction() { 
    document.getElementById("orange").selected = "true"; 
} 
</script> 

</body> 
</html> 

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_option_selected2

+0

이미 dropdownlist에 값이 있습니다. 이 함수를 사용해 보았습니다. Reset() { document.getElementById ("red"). checked = false; document.getElementById ("select"). selectedIndex = 0; } –

+0

그러나 확인란 만 작동합니다. –

+0

두 번째 예는 대답을 보여줍니다. id를