TODO supply a title
<script>
function my1()
{
document.getElementById("demo").innerHTML="my first JAVA_SCRIPT function";
}
</script>
<script src="js/test.js"></script>
<script src="js/jquery-2.2.3.min.js"></script>
TODO write content
我的web页面
一个段落
<script type="text/javascript">
var myCallBack1 = function(data){
console.log("this is myCallBack1");
console.log(data);
}
</script>
<script type="text/javascript" src="http://121735.tunnel.2bdata.com/test/ajax.php?callback=myCallBack1"></script>
<script type="text/javascript">
//生成js代码
var tempMyCallBack = myCallBack;
var url = "http://121735.tunnel.2bdata.com/test/ajax.php?callback=tempMyCallBack";
// 创建script标签,设置其属性
var script = document.createElement('script');
script.setAttribute('src', url);
document.getElementsByTagName('head')[0].appendChild(script);
//console.log(document.getElementsByTagName('head'));
</script>
<script>
document.write("this is title
");
document.write("this is page
");
function my2()
{
document.getElementById("demo").innerHTML="my second function";
}
var person1 = Object.create(person);
document.getElementById("demo").innerHTML = window.person.firstName;
document.getElementById("demo").innerHTML = typeof(undefined);
</script>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var xmlhttp;
var count = 0;
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue",
fullName : function() {
console.log( this.firstName + " " + this.lastName );
}
};
function fullName()
{
person.fullName();
}
function test1()
{
document.getElementById("demo").innerHTML = "extern function";
}
function windowAlter()
{
window.alert(5+6);
}
function writeDate()
{
// document.write(Date());
document.getElementById("demo").innerHTML = Date();
consoleLog();
}
function consoleLog()
{
var a = 1;
var b = 2;
var c = a + "volvo";
console.log(c);
}
function onMouseOver()
{
document.getElementById("demo").innerHTML = "onMouseOver";
}
function onMouseOut()
{
document.getElementById("demo").innerHTML = "onMouseOut";
}
function onMouseEnter()
{
document.getElementById("demo").innerHTML = "onMouseEnter";
}
function onMouseDown()
{
document.getElementById("demo").innerHTML = "onMouseDown";
}
//xmlHttp请求
function xmlHttpReq(url)
{
xmlhttp=null;
xmlhttp = new XMLHttpRequest();
if (xmlhttp!=null){
xmlhttp.onreadystatechange=xmlHttpRes;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
}
function xmlHttpRes()
{
// xmlHttp返回处理
if (xmlhttp.readyState==4){
// 4 = "loaded"
if (xmlhttp.status==200){
// 200 = "OK"
console.log("this is xmlHttpRes");
console.log(xmlhttp.responseText);
}
}
}
//回调函数
function myCallBack(data)
{
console.log("this is myCallBack");
console.log(data);
}
//ajax 和 getJSON 跨域请求方式
function parseMyJson()
{
//ajax 请求方式 回调函数参数由jquery参数生成,请求成功回调函数会调用success函数
$.ajax({
//url: "test.php?callback=?",
url: "http://121735.tunnel.2bdata.com/test/ajax.php",
type: "GET",
dataType: "jsonp",
jsonp:"callback",
data:{ "phone":"131621", "passwd":"123456"},
success: function(data){
console.log("this is ajax callback success");
console.log(data);
},
error: function(){
alert("fail");
}
});
//getJSON 请求方式 回调函数参数由jquery参数生成,请求成功回调函数会调用写好的function函数
$.getJSON("http://121735.tunnel.2bdata.com/test/ajax.php?callback=?",
{
"phone":"131621",
"passwd":"123456"
},
function(data){
console.log("this is getJSON callback success");
console.log(data);
});
}
1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
$result=json_encode($arr);
//var_dump($_GET['callback']);
if( isset($_GET['callback']) ){
$called=$_GET['callback'];
echo $called . "({$result})";
}else{
echo "({$result})";
}
//echo $result;
?>