Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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 .load()在ul li上不起作用单击_Javascript_Jquery_Html_Html Lists - Fatal编程技术网

Javascript .load()在ul li上不起作用单击

Javascript .load()在ul li上不起作用单击,javascript,jquery,html,html-lists,Javascript,Jquery,Html,Html Lists,这是我的密码 $(文档).ready(函数(){ $(“#工作”)。单击(函数(){ $(“#container”).load(“about/work.html”); }); $(“#配置文件”)。单击(函数(){ $(“#container”).load(“profile.html”); }); }); 添加事件。预防默认值 $(document).ready(function(){ $("#work").click(function(event){ event.pre

这是我的密码

$(文档).ready(函数(){
$(“#工作”)。单击(函数(){
$(“#container”).load(“about/work.html”);
});
$(“#配置文件”)。单击(函数(){
$(“#container”).load(“profile.html”);
});
});


添加
事件。预防默认值

$(document).ready(function(){
  $("#work").click(function(event){
    event.preventDefault(); //changed here
    $("#container").load("about/work.html");
  });
  $("#profile").click(function(event){
    event.preventDefault(); //changed here
    $("#container").load("profile.html");
  });
});

添加
event.preventDefault

$(document).ready(function(){
  $("#work").click(function(event){
    event.preventDefault(); //changed here
    $("#container").load("about/work.html");
  });
  $("#profile").click(function(event){
    event.preventDefault(); //changed here
    $("#container").load("profile.html");
  });
});

尝试在
上单击

$(document).ready( function() {
    $("#work").on("click", function() {
        $("#container").load("about/work.html");
    });
});

尝试在
上单击

$(document).ready( function() {
    $("#work").on("click", function() {
        $("#container").load("about/work.html");
    });
});

这里有两件事需要改变

1) 尽量不要将
href
值留空。如果这样做,浏览器将重定向到同一页面。如果可能,给它一个值
href=“#”

2)
单击事件中缺少
preventDefault()
函数

$(document).ready(function(){
    $("#work").click(function(e){
        e.preventDefault();
        $("#container").load("about/work.html");
    });
    $("#profile").click(function(e){
        e.preventDefault();
        $("#container").load("profile.html");
    });
});

这里有两件事需要改变

1) 尽量不要将
href
值留空。如果这样做,浏览器将重定向到同一页面。如果可能,给它一个值
href=“#”

2)
单击事件中缺少
preventDefault()
函数

$(document).ready(function(){
    $("#work").click(function(e){
        e.preventDefault();
        $("#container").load("about/work.html");
    });
    $("#profile").click(function(e){
        e.preventDefault();
        $("#container").load("profile.html");
    });
});

您是否检查了浏览器控制台上的任何错误?单击处理程序不会停止浏览器以执行链接的默认行为:转到
href
属性中定义的位置(空值=此位置)->不要将
href
保留为空字符串。给它一个值:
href=“#”
您是否检查了浏览器控制台上的任何错误?单击处理程序不会停止浏览器以执行链接的默认行为:转到
href
属性中定义的位置(空值=此位置)->不要将
href
保留为空字符串。给它一个值:
href=“#”