当用户点击“回复”按钮时,我有这段代码用于聚焦文本区域:
$('#reply_msg').live('mousedown', function() {
$(this).hide();
$('#reply_holder').show();
$('#reply_message').focus();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<div id="reply_msg">
<div class="replybox">
<span>Click here to <span class="link">Reply</span></span>
</div>
</div>
<div id="reply_holder" style="display: none;">
<div id="reply_tab"><img src="images/blank.gif" /> Reply</div>
<label class="label" for="reply_subject" style="padding-top: 7px; width: 64px; color: #999; font-weight: bold; font-size: 13px;">Subject</label>
<input type="text" id="reply_subject" class="input" style="width: 799px;" value="Re: <?php echo $info['subject']; ?>" />
<br /><br />
<textarea name="reply" id="reply_message" class="input" spellcheck="false"></textarea>
<br />
<div id="reply_buttons">
<button type="button" class="button" id="send_reply">Send</button>
<button type="button" class="button" id="cancel_reply_msg">Cancel</button>
<!--<button type="button" class="button" id="save_draft_reply">Save Draft</button>-->
</div>
</div>
它显示了回复表单,但是文本区域不会聚焦。我是通过AJAX添加文本区域的,这就是为什么我使用.live()
的原因。我添加的框(甚至通过AJAX添加#reply_msg
并在其上按下鼠标时有反应),但它不会聚焦在文本区域上。
mousedown
、focus
、mouseup
、click
。@canon,你能分享一下你从哪里得到的吗?我在规范的任何部分都找不到它: https://www.w3.org/TR/uievents/#events-focusevent-event-order, https://www.w3.org/TR/uievents/#legacy-uievent-event-order, https://www.w3.org/TR/uievents/#events-mouseevent-event-order - ScriptyChris