jQuery表单关注元素创建

nam*_*tax 5 jquery focus

寻找我的jQuery代码的一些帮助.

我正在使用simplemodal插件创建一个模态框

我掌握了创建的一个元件,其中包含一个表单的点击一个模式对话框....我想形式有重点textarea的领域当它出现时,但我不确定如何做到这一点..

这是我目前的代码..

    $('#showModal a').live('click',(function(){
      // Build Modal Box Container And Add to Page      
        $('<div id="osx-modal-content">\
            <div id="osx-modal-title"><h2>Please explain this song.</h2></div>\
            <div id="osx-modal-data"> \
            <p class="loaderGif"> <img src="http://localhost:8500/mxRestore/images/ajax-loader.gif"> </p>\
         </div>\
         </div>').appendTo('body');

         //Set Modal Box Options                
        $("#osx-modal-content").modal({
                // OPTIONS SET HERE
                overlayClose:true,
                onOpen:OSX.open,
                onClose:OSX.close
            });

         // I have a hidden form on the page...grab its HTML!!
         var modalForm = $('#addTmWrapper').html();

         // Dynamically build a text area and add to the form...
         // The text area from my hidden form wont show properly for some reason.....maybe a coldfusion issue

         var textField= ''
         textField+= '<textarea name=' + '"sMessage"' + 'id="sMessages"' + 'cols="62"' + 'rows="3"' + 'class="textarea word_count">' + '</textarea>'

         // Add hidden form to modal box, add textarea to form..
         // Then show it                    
         $('#osx-modal-data').html(modalForm ).find('#addTmForm')
                .prepend(textField)
                .show();
    return false
}));
Run Code Online (Sandbox Code Playgroud)

想知道当模态框出现时我怎么能让textarea有焦点?

任何帮助将不胜感激,谢谢

use*_*716 1

要将焦点集中到表单元素,请使用focus()

$('#myElement').focus()
Run Code Online (Sandbox Code Playgroud)