[英]Load a variable php page with jQuery
My goals is to load a div from any php page. 我的目标是从任何php页面加载div。 I'm using the jQuery function .load for this:
我为此使用jQuery函数.load:
$(document).ready(function(){
$('#crumb').load('example.php #hello');
});
</script>
I want example.php to be welcome.php or test.php or about.php. 我希望example.php是welcome.php或test.php或about.php。 It depends on which page is loaded within the container of the index.
这取决于在索引的容器中加载哪个页面。 Any ideas?
有任何想法吗?
Try this: 尝试这个:
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');
});
To do so consider the following: 为此,请考虑以下事项:
Javascript 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 的HTML
<a href="#" onclick="StartNow()">Begin</a>
<div id="GetDivResult" style="display: none;"></div>
<div id="crumb"></div>
This is a simple example so you get the idea behind it.. 这是一个简单的示例,因此您可以从中得到启发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.