전 그 때 나는 내 양식을 리셋 버튼 클릭하면 재설정하지 수 있는 작업 코드. 그러나, 이 후, 나는 내 코드는 갈수록 길어지고 있다는 doesn& # 39 더 이상 빗나갔다.
<div id="labels">
<table class="config">
<thead>
<tr>
<th colspan="4"; style= "padding-bottom: 20px; color:#6666FF; text-align:left; font-size: 1.5em">Control Buttons Configuration</th>
</tr>
<tr>
<th>Index</th>
<th>Switch</th>
<th>Response Number</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<form id="configform" name= "input" action="#" method="get">
<tr><td style="text-align: center">1</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" value="" id="number_one"></td>
<td><input style="background: white; color: black;" type="text" id="label_one"></td>
</tr>
<tr>
<td style="text-align: center">2</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id = "number_two" value=""></td>
<td><input style="background: white; color: black;" type="text" id = "label_two"></td>
</tr>
<tr>
<td style="text-align: center">3</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id="number_three" value=""></td>
<td><input style="background: white; color: black;" type="text" id="label_three"></td>
</tr>
<tr>
<td style="text-align: center">4</td>
<td><img src= "static/switch.png" height="100px" width="108px"></td>
<td id="small"><input style="background: white; color: black;" type="text" id="number_four" value=""></td>
<td><input style="background: white; color: black;" type="text" id="label_three"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="configsubmit" value="Submit"></td>
</tr>
<tr>
<td><input type="reset" id="configreset" value="Reset"></td>
</tr>
</form>
</tbody>
</table>
</div>
그리고 내 jQuery:
$('#configreset').click(function(){
$('#configform')[0].reset();
});
일부 소스 코드가 포함되어 있을 수 있는 '내가 내 위해 오레스트 ()' 방식을 작동합니까? 이전에 내가 사용하고 있었습니다.
<script src="static/jquery.min.js">
</script>
<script src="static/jquery.mobile-1.2.0.min.js">
</script>
방법 () '와' 오레스트 일하던.
<script src="static/jquery-1.9.1.min.js"></script>
<script src="static/jquery-migrate-1.1.1.min.js"></script>
<script src="static/jquery.mobile-1.3.1.min.js"></script>
이 이유 중 하나가 될 수 있는가?
$('#configreset').click(function(){
$('#configform')[0].reset();
});
Js 넣어 해야했다. 고안되었습니다 일했다.
그래서, 어떤 문제에 대해 언급한 at fault 삽입하십시오. 아마 you& # 39, re 충돌하는 문제를 가진 ID? 실제 실행 클릭 () 는?
편집: (# 39 m, 주석 달기 기능을 제대로 사용하지 않고 있기 때문에 I& 슬픈 sack) It& 직결됨 # 39 의 코드에 문제가 되지 않습니다. 이 때 해당 페이지의 컨텍스트로 작동하잖아 미세 꺼내라고요 you& 현재 사용 중인 이 때문에, 대신 # 39, re / javascript & 사용하여 어떤 특정 포함한다. 양식 데이터 것은 무언가 할 수 있다. # 39; d 시작 코드 수립하였습니다 아웃해야 i& 변 및 위치를 찾는 데 시도하시겠습니까 it& # 39, 상황을 잘. # 39, & # 39 sure& 만들기 위해 단지 내 말은,, 내가 할 수 있다고 가정합시다.
console.log($('#configform')[0]);
s # 39 의, 함수 및 smartupdate it& 오른쪽 클릭 한 형태입니다.
편집할지 2 부: 한 가지 분명한 것은 할 수 있습니다 (# 39 의 경우 it& 대상으로 하는 것은 올바른) 는 사용 [" input:reset";] (http://api.jquery.com/reset-selector/) 를 대신 뭐한테 사용하고 있습니다. 또한 i& # 39, d, s, s not 타겟대상 that& 제안하세요 같도다라고 it& # 39 # 39 를 잘못 알아 볼 일을 실제 시장을 겨냥하고 있다. 그냥 열고 있는 너, 토스 화이트하프 방화범 / 개발자 도구,
console.log($('#configreset'))
무엇을 보고 군요 그리고 우리는 이동 가능 할 수 있다.
이것은 실제로 that& # 39 의 Javascript 에서 수행됨 바닐라 보다 쉽게 그 중 한 것을 포함한다. 하지만 ',' t have a # 39 jquery doesn& 재설정하지 양식 방법을 HTML 요소 크기:, 다음과 같은 형태로 재설정하지 수 있도록 모든 필드
document.getElementById('configform').reset();
Jquery 를 통해 이렇게 할 경우 (다른 답을 알 수 있듯이 있습니다. '$ (& # 39, # # 39, configform&) [0] 오레스트 ()') 를 [0] '는' 같은 폼 '을 통해 직접 가져올 만한 요소를 가져오는 DOM 도쿠망스게테레멘트베이드'. 후자의 경우 모두 더 효율적이고 간단해진다는 외곽진입 표시되어도 (이후 함께 jQuery 외곽진입 먼저 프레젠테이션이든 수거 및 할 페치할 요소가 있는 반면, 바닐라 Javascript it 에서 방금 내려받습니다 요소를 직접).
<input type="reset">
<input type="button" onclick="this.form.reset();">
그러나 재설정하지 버튼은 훨씬 더 나은 선택입니다.
내가 사용하는 이 단순한 코드:
//reset form
$("#mybutton").click(function(){
$("#myform").find('input:text, input:password, input:file, select, textarea').val('');
$("#myform").find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
});
첫 번째 줄은 재설정하지 양식 투입물
$('form#myform').trigger("reset"); //Line1
$('form#myform select').trigger("change"); //Line2
두 번째 one 은 select2 재설정하지
$('form#myform select, form input[type=checkbox]').trigger("change"); //Line2
Id 가 = 이 같은 입력 유형 = 재설정하지 레세포름 추가하기만 수 있습니다.
<html>
<form>
<input type = 'reset' id = 'resetform' value = 'reset'/>
<!--Other items in the form can be placed here-->
</form>
</html>
됩니다 () 함수를 사용하여 가진 다음 jquery 가 다음과 같이 = 레세포름 요소에 대한 클릭하십시오.
<script>
$('#resetform').click();
</script>
양식 및 리셋이나 참고: 리셋 단추를 사용하여 css id = 인 레세포름 숨김니다 수도 있습니다.
<style>
#resetform
{
display:none;
}
</style>
이것은 단순한 솔루션 함께 포함한다. 작동하잖아 전역으로라는. 투명지에 볼 코드.
$('document').on("click", ".clear", function(){
$(this).closest('form').trigger("reset");
})
클래스 a 버튼을 추가하기에서는 선택해제합니다 모든 폼 리셋하려면 합니다. 예를 들면 다음과 같습니다.
<button class="button clear" type="reset">Clear</button>
다음 사용할 수 있습니다.
@using (Html.BeginForm("MyAction", "MyController", new { area = "MyArea" }, FormMethod.Post, new { @class = "" }))
{
<div class="col-md-6">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
@Html.LabelFor(m => m.MyData, new { @class = "col-form-label" })
</div>
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
@Html.TextBoxFor(m => m.MyData, new { @class = "form-control" })
</div>
</div>
<div class="col-md-6">
<div class="">
<button class="btn btn-primary" type="submit">Send</button>
<button class="btn btn-danger" type="reset"> Clear</button>
</div>
</div>
}
그럼 선택해제합니다 양식:
$('.btn:reset').click(function (ev) {
ev.preventDefault();
$(this).closest('form').find("input").each(function(i, v) {
$(this).val("");
});
});