jQuery将url变量传递给load函数

Adi*_*Adi 1 variables jquery load

我正在尝试使用load来重新加载当前页面的一部分(长篇故事为什么)但是我遇到了变量语法的问题.

以下是代码片段:

var pathname = window.location.pathname;
$('#menu').load("/cms.php #menu");
Run Code Online (Sandbox Code Playgroud)

我想用变量替换/cms.php,但是我遇到了纠正语法的问题.

任何帮助/建议都会得到很多批评.

一个.

Lia*_*amB 7

根据您的示例,要添加路径名var,请执行以下操作,但为什么要在Load字符串末尾指定"#menu".

var pathname = window.location.pathname; 
$('#menu').load(pathname +" #menu");
Run Code Online (Sandbox Code Playgroud)