在javaSript的注释中的语句只有在支持javaScript的浏览器上才能显现
不支持的浏览器要使用<noscript></noscript>
一旦使用<script language = "javaScript" src = "sa.js">语句块</script>则语句块不能再被使用.调用的是sa.js
这是两种定义字符串的方式
var value1 = '100';
var value2 = "kill you";
这是两种定义字符串的方式
var value5 = " world";
var value6 = (value5+value2).search("k");
var value7 = (value5+value2).replace("k",'c');
document.writeln(value6);这里得到6
document.writeln(value7);这里得到 worldcill you
big: Returns the string in big tags
blink: Returns the string in blink tags
bold: Returns the string in b tags
fixed: Returns the string in tt tags (for fixed-width display)
fontcolor: Returns the string in font tags with the color
attribute set to the color you specify as an argument
fontsize: Returns the string in font tags with the size attribute
set to the size you specify as an argument
italics: Returns the string in i tags
small: Returns the string in small tags
strike: Returns the string in strike tags (for a strikethrough
effect)
sub: Returns the string in sub tags (for a subscript effect)
sup: Returns the string in sup tags (for a superscript effect)
toLowerCase: Returns the string with all lowercase characters
toUpperCase: Returns the string with all upper case characters
variableName.big();
variableName.fontcolor(“red”);
variableName.toLowerCase();
document.writeln(value7.big());这样字体就变大了.
var finalString = firstString.bold().toLowerCase().fontcolor(“red”);以上的各个函数也可以集合使用
<font color=”red”><b>my string</b></font>就是以上语句的功效
for(var i=0;i<5;i++)
{
myArray1[i] = i;
document.writeln(myArray1[i]);
}
for(i=0;i<3;i++)//这样不会产生错误.和java不同.
{
document.writeln(myArray2[i]);
}
html和javascript都是在那里错才不显示.而并不是不能用浏览器浏览.
window.alert("hello");显示警告对话框
window.confirm("bye");显示确定对话框
function hello()
{
window.alert("hello");
}
<a href = "#" onClick = "hello();">onClick</a>//点击显示警告
<a href = "javascript:hello();">javascript</a>点击显示警告
这两句必须都放在<script></script>之外
<body onLoad = "warning();">这了调用的一般不是有参数的函数.
</body>
for(var i=0;i<4;i++)循环可以这样些也可以这样
for(i=0;i<4;i++)
也就是说变量可以不声明就使用
很奇怪
<head>
<script>
<!--
function warning()
{
window.alert("hello");
}
function firm()
{
return window.confirm("Open it?");
}
window.setTimeout("firm()",5000);
//-->
</script>
</head>
<body onLoad = "warning();">
<script>
var ok=firm();
...
</script>这里竟然先调用firm() 而后调用warning();
window.setTimeout("firm()",5000);5秒后自动跳出confirm对话框
function hello() {
window.alert(“Hello”);
window.setTimeout(“hello()”,5000);
}
这个每隔5秒的跳出confirm
var a = window.setTimeout("firm()",3000);
window.clearTimeout(a);用于取消时间调度
<body onUnload = "warning()">退出本页面是调用函数
var haveJava = navigator.javaEnabled();浏览器可用java则返回true
document.write("<p><strong>Dynamic Content</strong></p>");当传入write的参数含有html标签时,输出时可以自动转换格式
这句话就显示加粗后的字样
本文介绍了JavaScript的基本语法,包括字符串操作、数组使用、条件判断及函数调用等,并演示了如何利用DOM进行页面元素操作和使用定时器实现弹窗提示。
3万+

被折叠的 条评论
为什么被折叠?



