2016-09-30 3 views
0

현재 기본적으로 아무 것도 표시하지 않는 div 클래스가 있지만 도움말 텍스트가 포함 된 경우 도움말 텍스트의 값을 원합니다. 내 생각 엔 뭔가 같은도움말 텍스트가 화면에 표시되는 경우?

아래는 내 사업부

<div class="alert alert-info col-md-12" id="ProfHelpAlert" role="alert" style="display:none"> 
    <i class="fa fa-info-circle" aria-hidden="true"></i> 
    <strong class="notification" id="ProfHelp"></strong> 
</div> 

입니다 display.show 드롭 다운 메뉴에서 값 도움말 텍스트가 포함 된 경우 이것은 당신이 당신의 도움말 메시지를 표시 할 건가요 내 자바 스크립트

$('#profession').on('change', function (e) { //Gets the ID of profession drop down list 
    var selectedVal = $(this).val(); //Variable selectedVal this . value 
    $.ajax({ //Ajax declared 
     type: 'GET', //Its a get 
     url: "@Url.Action("GetenquiryTypes", "UnauthEnquiry")", //It goes to the enquiry controller method GetenquiryTypes 
     dataType: 'json', //Datatypes JSON 
     data: { SelectedProfession: selectedVal }, //data is SelectedProfession: selectedVal 
     success: function (json) { //Jquery Parse Json data from server on ajax success 
      $('#ProfHelp').html(json.helptext); 

      var targetDropdown = $('#enquirytype') //Var targetDropDropdown goes to dropdown ID enquiry type 
      targetDropdown.empty(); //target empty dropdown 
      $("<option />", { 
       val: "", 
       text: "Please select enquiry type" //Select enquiry type 
      }).appendTo(targetDropdown); //add to the target dd 
      if (json.enquiryTypes.length > 0) { //if JASON data from server greater then 0 
       for (var EnquiryType in json.enquiryTypes) { //go through each EnquiryType in JSON 
        $("<option />", { 
         val: json.enquiryTypes[EnquiryType].EnquiryId, //mapping 
         text: json.enquiryTypes[EnquiryType].Enquiryname //mapping 
        }).appendTo(targetDropdown); //add to drop down 

       }; 
      } 
     } 
    }); 
}); 

답변

0

입니다 아약스 메서드가 성공하면? 그렇다면이게 당신이 찾고있는 것입니까?

success: function(json) { 
    //... add to end of method 
if(json.helptext) { 
    $('#ProfHelpAlert').show(); 
} 
} 

선택의 가치에 대한 비교가 필요합니까?

success: function(json) { 
    //... add to end of method 
if(json.helptext == selectedVal) { 
    $('#ProfHelpAlert').show(); 
} 
} 
+0

임 도움말 텍스트가 드롭 다운 값이있는 경우, 코드에 당신이 "도움말 텍스트가 존재하는"것을 아는 경우 다음 @matthew 부과 – Sam

+0

을 보여 말하려고? 옵션 선언에서 "텍스트"매개 변수를 의미합니까? –

+0

if (json.helptext! = undefined && json.helptext! = '') { $ ('# ProfHelp') .html (json.helptext) .show(); /////// } 이 작업은 수행되지 않습니다. – Sam

관련 문제