【发布时间】:2015-06-28 18:30:03
【问题描述】:
我有一个简单的转换,其中一条消息说“单击此处输入”之类的内容,这是一个 div,单击该 div 时会隐藏此 div 并显示带有闪烁光标的文本区域。当页面最初加载时,我通过 onload 获得焦点,但我在之后,在需要时触发焦点。
所以我有这样的东西:
界面
<div id="message" onclick="showPad();"><span class="message">Click to write</span></div>
<form name="entry">
<textarea id="writingpad" name="writingpad" placeholder="write here"></textarea>
</form>
javascript
<script>
function showPad() {
document.getElementById('message').style.display = "none";
document.getElementById('writingpad').style.display = "inline-block";
// this is what I've tried for focus
document.entry.writingpad.focus(); // didn't work
$('#writingpad').live('focus', function() {
// document.entry.input.focus(); possibly redundant
}
$('#writingpad').focus(); // doesn't work
}
</script>
工作脚本
function showPad() {
$('#writingpad').focus();
}
【问题讨论】:
标签: javascript jquery