正在寻求有关我的 jQuery 代码的帮助。
我正在创建一个模式框,使用 simplemodal plugin
我正在设法在单击一个元素时创建一个模式框,其中包含一个表单......我希望表单在出现时将焦点集中在文本区域字段上,但我不确定如何实现这一点..
这是我当前的代码..
$('#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
}));
想知道如何在模态框出现时使文本区域获得焦点?
如有任何帮助,我们将不胜感激,谢谢
请您参考如下方法:
要将焦点赋予表单元素,请使用 focus()。
$('#myElement').focus()
