programing

jQuery choosed plugin으로 양식을 재설정하려면 어떻게 해야 합니까?

mailnote 2023. 10. 28. 08:08
반응형

jQuery choosed plugin으로 양식을 재설정하려면 어떻게 해야 합니까?

나는 많은 것을 가지고 있습니다.selectJquery Choosen 플러그인을 사용하는 형태의 요소.양식을 초기화하려면 어떻게 해야 합니까?다음은 작동하지 않습니다.

<input type="reset" />

필드의 값을 재설정한 다음에liszt:updated업데이트하기 위한 입력에 대한 이벤트, 나는 여기서 작동하는 예시를 만지작거렸습니다.

http://jsfiddle.net/VSpa3/3/

$(".chzn-select").chosen();
$('a').click(function(){
    $(".chzn-select").val('').trigger("liszt:updated");
});​

선택한 v1.0 릴리스 이후로 트리거를 이제 'choosed:update'라고 합니다.이 새 버전을 사용하는 사람은 다음을 사용하여 업데이트를 트리거해야 합니다.

$(".chosen-select").val('').trigger("chosen:updated");

선택한 v1.0 릴리스 이후로 트리거를 이제 'choosed:update'라고 합니다.이 새 버전을 사용하는 사람은 다음을 사용하여 업데이트를 트리거해야 합니다.

$(".chosen-select").val('').trigger("chosen:updated");

이것을 시도해 볼 수 있습니다.

$('select').chosen('destroy');  

$('select').prop("selectedIndex", -1);   
$('select').chosen();

작업을 재설정하려면 다음을 사용합니다.

$("input[type='reset'], button[type='reset']").click(function(e){
    e.preventDefault();

    var form = $(this).closest('form').get(0);
    form.reset();

    $(form).find('select').each(function(i, v) {
        $(v).trigger('chosen:updated');
    });
}

이전 옵션 중에 저에게 적합한 것은 없습니다.예전 학교처럼 해야 했어요 네이티브 자바스크립트를 사용해도 코드는 다음과 같습니다.

$('#dllSample option').each(function(){
     $(this)[0].selected = false;   
});
$("#dllSample").trigger("chosen:updated");
$("#Your_id").trigger("chosen:updated");

이거 나한테 통했어요.

입력 내용이 내부에 있다고 가정하여 보다 번거롭지 않게 접근할 수 있습니다.<form>태그:

<form>
    <!-- your selects go here and any other input fields -->
    <input type="reset" value="Reset"> 
</form>

이것이 제가 할 일입니다.

$("input[type='reset'], button[type='reset']").click(function(e){
      setTimeout(function(){ $("select").trigger("chosen:updated"); }, 50);
});

여기에 fiddle.

여기 있는 어떤 대답도 내게 맞지 않았습니다.다중 속성과 함께 selected select를 사용하고 있습니다.일반적인 제출 양식 버튼도 효과가 없었습니다.그래서 클릭할 때 이것을 하는 기능이 있습니다.

//Gets the selected values
var selected = [];
    for (var option of document.getElementById('mySelect').options) {
        if (option.selected) {
            selected.push(option.value);
        }

    }

//Resets the form
document.getElementById('form1').reset();

//Chosen values doesnt get reset, so we do this manually
//Removes the values selected by clicking on the x icon
$link = $('a.search-choice-close');
            var i;
            for (i = 0; i < selected.length; i++) {
                $link[i].click();
            }

선택한 선택 항목이 호출된 경우를 재설정해야 합니다.

이렇게 합니다.

jQuery.fn.chosen_reset = function(n){
  $(this).chosen('destroy');
  $(this).prop('selectedIndex', 0);
  $(this).chosen(n)
}

이 함수를 이렇게 부르고 옵션을 인수로 사용합니다.

$('select').chosen_reset({width:'369px'});

jQuery에서는 이와 같은 것이 효과가 있을 것입니다.

<input name="Text1" id="something" type="text">

<input type="reset" id="reset_me"/>


$("#reset_me").click(function() { 
$("#something").val("");
});

언급URL : https://stackoverflow.com/questions/7897760/how-can-i-reset-a-form-with-jquery-chosen-plugin

반응형