2014-04-21 3 views
0

나는 JQuery와 스크립트에 숨겨진 필드 값을 설정하고 있지만 숨겨진 필드가 [개체 개체] 여기숨겨진 필드 값은 포함 [개체 개체]

는 값입니다을 포함하는 값을 반환

"[개체 개체, 22 4 월 2014"

스크립트

  var indx = 0; 
      var hdfield = $('#hdlstVisitDates'); 
      var lst = $('#lstVisitDates'); 
      var options = $('#lstVisitDates option'); 
      $(options).each(function() { 

       if (indx = 0) { 
        hdfield = $(this).val(); 
        indx = 1; 
       } 
       else 
       { hdfield = hdfield + ',' + $(this).val(); } 
      }); 

      $('#hdlstVisitDates').val(hdfield); 
+1

그럼 당신은'hdfield'에 jQuery를 객체를 할당하고, 당신이 다른 무엇을 기대 않았다해야한다 항상 false로 평가됩니다 if (indx = 0) {이? – Hatsjoem

답변

1

hdfield$('#hdlstVisitDates')으로 초기화하는 것은 poi 개봉 나중에 값을 덮어 쓸 것 때문에 ntless, 또한 당신은 if (indx == 0) {

 var indx = 0; 
     var hdfield;// = $('#hdlstVisitDates'); why do this? 
     var lst = $('#lstVisitDates'); 
     var options = $('#lstVisitDates option'); 
     $(options).each(function() { 

      if (indx == 0) { 
       hdfield = $(this).val(); 
       indx = 1; 
      } 
      else 
      { hdfield = hdfield + ',' + $(this).val(); } 
     }); 

     $('#hdlstVisitDates').val(hdfield); 
+0

감사합니다. == :) – user1263981

2
// initialise hdfield with val() 
var hdfield = $('#hdlstVisitDates').val(); 

그렇지 hdfield 입력 요소 [object Object]이 변환 될 문자열 연결 것