2011-12-19 81 views
0

我正在使用cakephp 1.3和fancybox ..我已經成功地在fancybox中放置了一個表單。現在我想將光標集中到輸入字段之一。我很厭倦了,不想下面jquery fancybox輸入焦點

<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代碼我嘗試下面的事情

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

$('#answer').focus(); 
我script.But沒有好結果

>可以在任何有一點指出我錯了我的代碼。提前感謝。

我的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(); 
}, 

希望它可以幫助

+0

感謝名單哥哥......我是壞的腳本 – jack

0

我做了選擇ID是錯誤的。我從我用來彈出fancybox的鏈接和選擇器字段中使用相同的ID,即answer。 我將表單域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')); ?>