我有一个函数 ajaxinclude() ,它包含页面的内容。当写成这样时,它可以完美地工作:
<div>
<script type="text/javascript">
ajaxinclude("info/content/About.php")
</script>
</div>
现在,我想要一个点击按钮。因此,
<button onclick="document.getElementById('aaa').innerHTML = '<script type='text/javascript'>ajaxinclude(\'info/content/About.php\');</script>">Hello</button>
但这不起作用。
另一种方法是
<button onclick="document.getElementById('aaa').innerHTML = '<script type='text/javascript'>' + ajaxinclude('info/content/About.php') + '</script>">Hello</button>
但这也不起作用。
这是我的 ajaxinclude() 函数:
var rootdomain = "http://" + window.location.hostname;
function ajaxinclude(url) {
var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.open('GET', url, false)
page_request.send(null)
writecontent(page_request)
}
function writecontent(page_request){
if (window.location.href.indexOf("http")==-1 || page_request.status==200)
document.write(page_request.responseText)
}
如何,如何在按钮单击时包含文本?
PS:我不想要 jQuery。