JS样式常用的有两种:内嵌样式 ,外联样式;
内嵌js代码:
<script> //内嵌样式
function random()
{
document.getElementById("random")。innerHTML = "ojbk";
}
</script>
html中调用js内嵌样式代码:
<button type="button" onclick="random()" class="buttonstyle1">点击验证</button>
外联js样式表代码:
文件内容:
function random()
{
document.getElementById("random")。innerHTML ='ojbk';
}
在HTML中引入js外联代码(放在head标签中,对整个页面起作用):
<head>
<meta charset="UTF-8">
<title>简易验证码</title>
<script type="text/javascript" rel="script" src="javascript.js"></script> //此处注意你的js文件的相对路径
</head>
HTML调用外联js代码:
<button type="button" onclick="random()" class="buttonstyle1">点击验证</button>
注释:这个其实和上面那个HTML中调用的代码是一样的!
注意:在实训中,要注意你的js文件的相对路径,路径错误将无法调用!!! JS的调用和CSS很相似。
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64758.shtml