我想用这个加载一些PHP页面到div标签,但是这段代码不起作用;
<a href="#" id="dahili"><span>Dahili Branşlar</span></a>
<a href="#" id="cerrahi" ><span>Cerrahi Branşlar</span></a></li>
<script>
var yuklenecek = document.getElementById(id);
$("#"+yuklenecek).on("click", function(){
$("#orta_load").load(yuklenecek+".php");
});
</script>
<div id="orta_load">
when ı click to buton that which ı choose : should load dahili.php or cerrahi.php page in here
</div>
&#13;
答案 0 :(得分:0)
你需要这个:
$(".loaddiv").click(function() {
var url = $(this).attr("id") + ".php";
$("#orta_load").load(url);
console.log("loading " + url);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" id="dahili" class="loaddiv"><span>Dahili Branşlar</span></a>
<a href="#" id="cerrahi" class="loaddiv"><span>Cerrahi Branşlar</span></a>
<div id="orta_load">
when ı click to buton that which ı choose : should load dahili.php or cerrahi.php page in here
</div>
&#13;
注意jQuery函数如何将click处理程序分配给每个<a>
,然后使用其id
来确定php文档。