本文介绍了jQuery窗体焦点跟随元素创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
我正在设法在一个元素的点击上创建一个模式框,一个形式....我想表单,当它出现在textarea领域的焦点,但我不确定如何实现这一点。
这是我的当前的代码。
$('#showModal a')。live('click',(function(){
//创建模态框容器并添加到页面
$('< div id =osx-modal-content> \
< div id =osx-modal-title >< h2>请解释这首歌曲。< / h2>< / div> \
< div id =osx-modal-data> \
< p class =loaderGif>< img src =http:// localhost:8500 / mxRestore / images / ajax-loader.gif>< / p> \
< / d iv> \
< / div>')。appendTo('body');
设置模态框选项
$(#osx-modal-content)。modal({
//选项设置在这里
overlayClose:true,
onOpen:OSX.open,
onClose:OSX.close
});
//我在页面上有一个隐藏的表单...抓住它的HTML!
var modalForm = $('#addTmWrapper')。html();
//动态构建一个文本区域并添加到表单中...
//我的隐藏表单中的文本区域由于某种原因不会正确显示.....也许是一个coldfusion发行
var textField =''
textField + ='< textarea name ='+'sMessage'+'id =sMessages'+'cols =62 ''''''''''''''''class =textarea word_count>'+'< / textarea>'
//将隐藏表单添加到模式框中, b $ b //然后显示
$('#osx -modal-data')。html(modalForm).find('#addTmForm')
.prepend(textField)
。显示();
返回false
}));
想知道如何让textarea在模态框出现时有焦点?
任何帮助将不胜感激,谢谢 试试这个:
var aSet = $('selector');
aSet [0] .focus();上面的焦点适用于元素而不是jQuery对象。
Looking for some assistance with my jQuery code.
I am creating a modal box, using the simplemodal plugin
I am managing to create a modal box on the click of an element, which contains a form....I would like the form to have focus on the textarea field when it appears, but am unsure of how to achieve this..
Here is my current code..
$('#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
}));
Wondering how I can make the textarea have focus when the modal box appears?
Any help would be appreciated, thanks
解决方案 try this:
var aSet = $('selector');
aSet[0].focus();
the focus above applies to Element not jQuery Object.
这篇关于jQuery窗体焦点跟随元素创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!