继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

php加载javascript的方法

斯蒂芬大帝
关注TA
已关注
手记 76
粉丝 7
获赞 21

1、将javascript写成js文件,然后在php文件中将js文件放到<head></head>部分。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>php加载js的方法</title>

<script language="javascript" type="text/javascript"  src="NotNullCheck.js">

</script>

</head>

<body>

<h1 align="center">php加载js的方法</h1>


2、直接将javascript脚本写到php文件中。<head></head>或<body></body>都可。

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>测试连接数据库</title>

<script language="javascript" type="text/javascript" >

function notnullcheck()

{

    var hostname=document.getElementById("host").value;

    var name=document.getElementById("username").value;

    var pass=document.getElementById("password").value;

    if(hostname=="")

    {

        alert("服务器地址不能为空!");

        return false;

    }

        if(name=="")

    {

        alert("用户名不能为空!");

        return false;

    }

        if(pass=="")

    {

        alert("密码不能为空!");

        return false;

    }

}

</script>

</head>

<body>

<h1 align="center">数据库连接测试</h1>

</body>


3、通过

echo "<script type='text/javascript' language='javascript' src='NotNullCheck.js'></script>";

加载js文件。

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP