2013-08-09 2 views
0

일부 내용을 Ajax로로드하는 동안 옵션을 선택해야합니다. 그런데jquery로 선택한 드롭 다운 옵션을 선택하십시오.

$(document).ready(function(){ 
    $('#select').on('change', function(){ 
    //Here $(this) is the "select" select; 
    if($(this).val() !== '1'){ 
     $(this).val('1'); //You can set val to select the option which you want. 
    } 
    ..... 
    }); 
}); 

: HTML : :

<select id="select" name="select"> 
    <option value="1">Yes</option> 
    <option value="0">No</option> 
</select> 

JS 여기에 코드 ..

<select id="select" name="select" onchange="onClick(this.options[this.selectedIndex].value)"> 
    <option value="1" >Yes</option> 
    <option value="0">No</option> 
모든
function onClick(value) { 
    var p = document.getElementById('select'); 
    if(p.value != value) { 
      $('select>option:eq(1)').prop('selected',true)); /*this portion doesn't work */ 
    } 
    setTimeout("onClick(1)",5000); /* value 1 for display yes which will display by ajax load file add.php but i can't select yes which already set by ajx url and load content */ 
    } 
    $.ajax({ 
     url:'add.php', 
     type:'GET', 
     data : {id : value}, 
     success : function(response){ 
      $('div#content').html(response); 
     } 
    }); 
}});} 
+3

첫 번째 작업은 자바 스크립트에서 수많은 구문 오류를 수정하는 것입니다. 다음은 여기서 달성하고자하는 것을 설명하는 것입니다. –

+0

삭제하십시오! –

+0

아약스 응답 후 데이터를 분석하고 그 후에 select를 변경하겠습니까? – Sergio

답변

0

먼저,이 같은 당신의 코드를 업데이트 할 수있다 , 나는 아직도 당신의 코드의 나머지 부분을 따라갈 수 없다. 희망이 당신을 위해 이해할 수 있습니다.

관련 문제