0

我有一个按钮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 代码:

<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();

上面的不行。。

4

3 回答 3

1

这是因为 <a href="#"删除#href属性本身

写成——

<a id="updateLogButton">Update Log</a>

CSS -

a{ cursor: pointer; }
于 2012-10-09T07:06:38.097 回答
0

Try this I think you should use fadeToggle() instead of checking div is visible or not and after that set focus

    //hide div on page load
$('#updateLogText').hide();

$('#updateLogButton').click(function() {

          $('#updateLogText').fadeToggle();       
          $('#updateLogText').focus();       
    }

);

http://jsfiddle.net/cF4Bb/5/

于 2012-10-09T07:10:37.920 回答
0

Ud 下面的行它会起作用,你没有在引号中给出-1,为什么要专注于不来

$("#updateLogText").attr("tabindex",-1).focus();

于 2013-11-22T16:59:52.033 回答