我想设置 jQuery 加载目标。 下面的代码是工作。
<script>
$(document).ready(function() {
$(".first").click(function(){
var str=$(this).attr("value"); /
$(".sencond").hide();
$("#shows").html("wait ... ");
$("#shows").show();
$("#shows").load('load.php?str='+str);
})
})
</script>
我想将加载目标更改为 $("#shows"(.load("'+str+'.php"(; 但这不是工作。
怎么了?
你可以这样做吗,str周围不需要引号('str'
(。
$("#shows").load( str+ ".php")
$("#shows").load("'+str+'.php");
它会生成字符串作为'strvalue'.php
并且找不到该页面的问题。
这是工作代码:
<script>
$(document).ready(function() {
$(".first").click(function(){
var str=$(this).attr("value");
$(".sencond").hide();
$("#shows").html("wait ... ");
$("#shows").show();
$("#shows").load(str+'.php');
})
})
</script>
确保加载PHP页面应该在那里!!
使用 js 模板字符串
$("#shows").load(`${var}.php`)