我点击按钮updateLogButton
时会显示div,再次点击时会隐藏它。我有这部分工作。每次点击按钮时,唯一的问题是焦点移动到页面的开头,而不是关注div中的内容。
JQuery代码:
//hide div on page load
$('#updateLogText').hide();
$('#updateLogButton').click(function() {
if ($('#updateLogText').is(':visible')){
//hide div if content is visible
$('#updateLogText').fadeOut();
}else{
$('#updateLogText').fadeIn();
}
});
HTML code:
<tr>
<td><a href="#" id="updateLogButton">Update Log</a></td>
</tr>
<tr>
<td colspan="3" >
<div id="updateLogText" style="width:100%;">
<?php echo $data['updates']; ?>
</div>
</td>
</tr>
有人知道如何实现这一目标吗?我查看了JQuery文档并尝试了:
$("#updateLogText").focus();
$("#updateLogText").attr("tabindex",-1).focus();
以上不起作用..
答案 0 :(得分:1)
这是因为<a href="#"
删除#
或href
属性本身
将其写为 -
<a id="updateLogButton">Update Log</a>
css -
a{ cursor: pointer; }
答案 1 :(得分:0)
试试这个我认为你应该使用fadeToggle()
而不是检查div是否可见
之后设定焦点
//hide div on page load
$('#updateLogText').hide();
$('#updateLogButton').click(function() {
$('#updateLogText').fadeToggle();
$('#updateLogText').focus();
}
);
答案 2 :(得分:0)
Ud在行之下它会起作用你没有在引号中给出-1,为什么要关注不要提交
$( “#updateLogText”)ATTR( “tabindex属性”, - 1).focus();