Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery在我的代码中不工作_Javascript_Jquery - Fatal编程技术网

Javascript jquery在我的代码中不工作

Javascript jquery在我的代码中不工作,javascript,jquery,Javascript,Jquery,我尝试在我的网站上使用jQuery,但它似乎不起作用。这个代码不起作用。当我点击test时,它不会隐藏。请帮忙。谢谢 这是我的Html文件: <!DOCTYPE html> <html> <head></head> <body> <p id="#test">Hello world !</p> <script src="js/jquery.js"><

我尝试在我的网站上使用jQuery,但它似乎不起作用。这个代码不起作用。当我点击test时,它不会隐藏。请帮忙。谢谢

这是我的Html文件:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <p id="#test">Hello world !</p>

        <script src="js/jquery.js"></script>
        <script type="text/javascript" src="js/code.js"></script>
    </body>
</html>

您的html错误,请删除哈希符号:


$test表示选择id等于test的元素

尝试用\\

$(document).ready(function() {
    $('#test').click(function() {
        $('#test').hide();
    }); 
});
<p id="test">Hello world !</p> // this is right
<p id="#test">Hello world !</p> // this is wrong
$(document).ready(function() {
    $('#test').click(function() {
        $(this).hide();
    }); 
});
$(document).ready(function() {
    $('#\\#test').click(function() {
        $('#\\#test').hide();
    }); 
});