1

我有一个页面显示一些文本。我想隐藏该文本并仅在有人单击链接/按钮时显示它。我尝试使用这个:

<script>
    function f()
    {          
      document.getElementById("line").focus();
      document.getElementById("help").innerHTML = helptext();
    }

    $(function(){
       $('p[id=help]').hide();
       $('a[title=showcmd]').click(function(){
            $('p[id=help]').slideIn();
            $(this).hide();
            f();
       });
    });

    </script>

但它不起作用。

4

4 回答 4

4

改变:

$('p[id=help]').slideIn();

$('p[id=help]').slideDown();

jquery中没有slideIn

于 2013-01-02T12:05:23.673 回答
2

控制台所示slideIn, jQuery中没有函数:

未捕获的类型错误:对象 [object Object] 没有方法“slideIn”

测试代码:

function f()
    {          
      document.getElementById("help").innerHTML = "Trying out Jquery";
    }

$(function(){
   $('p[id=help]').hide();
   $('a[title=showcmd]').click(function(){
        $('p[id=help]').slideIn();
        $(this).hide();
       f();
   });
});

我想您想使用slideUpslideDown,或者可能是 fadeIn

对于未来的问题,我建议您查看开发人员控制台:它始终显示错误消息,通常以足够清晰的方式显示代码中的确切位置。

于 2013-01-02T12:03:33.237 回答
1

如果它不起作用,请尝试阻止点击事件,如下所示。

<script>
    function f()
    {          
      document.getElementById("line").focus();
      document.getElementById("help").innerHTML = helptext();
    }

    $(function(){
       $('p#help').hide();
       $('a[title=showcmd]').click(function(e){
            e.preventDefault();
            $('p#help').slideDown('slow');
            $(this).hide();
            f();
       });
    });

    </script>
于 2013-01-02T12:09:16.667 回答
0

使用slideDown()代替slideIn()

于 2013-01-02T12:10:23.627 回答