[英]Load a variable php page with jQuery
我的目標是從任何php頁面加載div。 我為此使用jQuery函數.load:
$(document).ready(function(){
$('#crumb').load('example.php #hello');
});
</script>
我希望example.php是welcome.php或test.php或about.php。 這取決於在索引的容器中加載哪個頁面。 有任何想法嗎?
嘗試這個:
function $_GET(q, s) {
s = s ? s : window.location.search;
var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
/*
* Edited here
*/
$(document).ready(function(){
$('#crumb').load(($_GET('p') !== undefined ? ('index.php?p=' + $_GET('p')) : 'welcom.php') + ' #hello');
});
為此,請考慮以下事項:
Java腳本
function GetDiv(url,tdiv) {
$("#GetDivResult").load(url,function() {
HandleResult(tdiv);
});
}
function HandleResult(tdiv){
$("#crumb").html($(tdiv).html());
}
function StartNow(){
var url = prompt("Enter the URL");
var tdiv = prompt("What DIV you want to show? example: #hello");
GetDiv(url,tdiv);
}
的HTML
<a href="#" onclick="StartNow()">Begin</a>
<div id="GetDivResult" style="display: none;"></div>
<div id="crumb"></div>
這是一個簡單的示例,因此您可以從中得到啟發。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.