2011-12-19 2 views
0

cakephp 1.3 및 fancybox를 사용 중입니다. fancybox.now에 양식을 입력 할 수 있도록 입력 필드 중 하나에 커서를 집중시키고 싶습니다. 나는 일jquery fancybox 입력 포커스

'onComplete' : function() { 
       $('#fancybox-frame').contents().find('#answer').focus(); 
      }, 

내 script.But 더 좋은 결과에서

$('#answer').focus(); 

> 할 수있는 다음과 같은 노력

<script type="text/javascript"> 
jQuery(document).ready(function() { 
//document.getElementById('frmname.answer').focus(); 
jQuery("a#answer").fancybox({ 
     'transitionIn' : 'elastic', 
     'transitionOut' : 'elastic', 
     'speedIn' : 600, 
     'speedOut' : 200, 
     'overlayShow' : false, 
     'href' : this.href, 
}); 

}); /* */ 
</script> 

아래에 주어진 많은 thing.My 코드를 시도 꽤 피곤 하나의 잘못된 지적은 내 코드로하고있다. 미리 감사드립니다.

내 fancybox 내용은 다음과 같이이다 :

<div style='display:none'> 
    <div id='reply'> 

     <h1>Reply For <?php echo $offer['OfferBoard']['headline'] ?></h1> 


     <ul class="nrml_list" > 

       <?php echo $this->Form->create('OfferAnswer',array('id'=>'frm','name'=>'frmname'), array('action' => 'reply/'.$offer['OfferBoard']['id'],'inputDefaults'=> array('label'=>false))); ?> 


       <li> 
        <div class='ulabel' style="float:right;" >Reply Text</div> 
        <div> 
         <div class="left"><?php echo $form->textarea('answer',array('class'=>'tarea1','label'=>FALSE,'id'=>'answer')); ?></div> 
         <div class="clear"></div> 
         </div> 
       </li> 

       <li> 
        <div class='ulabel' ></div> 
        <div> 
         <div class="left"><?php 
           $attributes=array('type'=>'checkbox','div'=>false,'value' => '1','hiddenField' => false,'label'=>FALSE); 
           echo $this->Form->input('copy_to',$attributes)." Send Copy "; 
         ?></div> 
         <div class="clear"></div> 
         </div> 
       </li> 



     </ul> 
      <?php echo $this->Form->end('Reply'); ?> 



    </div> 

답변

3

시도 :

 
//without quotes in onComplete, this worked for me 
onComplete: function() { 
    $('#answer').focus(); 
}, 

는 내가 선택 ID와 실수를

+0

고맙습니다 오빠는 ... 내가 스크립트 나쁜입니다 – jack

0

도움이되기를 바랍니다. 나는 fancybox을 팝업하는 데 사용한 링크와 선택기 필드 (예 : answer)에서 동일한 ID를 사용하고있었습니다. 양식 필드 ID의 이름을 ans ...으로 바꿨습니다. 덕분 @Sudhir는 올바른 코드는 다음과 같다 :

<script type="text/javascript"> 
jQuery(document).ready(function() { 
//document.frm.elements['data[OfferAnswer][answer]'].focus(); 
jQuery("a#answer").fancybox({ 
     'transitionIn' : 'elastic', 
     'transitionOut' : 'elastic', 
     'speedIn' : 600, 
     'speedOut' : 200, 
     'overlayShow' : false, 
     'href' : this.href, 
     onComplete : function() { 
        $('#ans').focus(); 
         }, 
}); 

}); /* */ 
</script> 

새로운 폼 요소는 다음과 같습니다

<?php echo $form->textarea('answer',array('class'=>'tarea1','label'=>FALSE,'id'=>'ans')); ?>