JavaScript in 10 Steps or Less
没有按别人的推荐,学什么圣经类的js书,而是随便挑了本《JavaScript in 10 Steps or Less》。
花了3个小时,看了30个task。
讲的非常浅显详细。虽然是E文,但很浅显易懂。
task31:
Calling Functions from Tags
One of the benefits of JavaScript is to be able to tie interactivity to elements of the HTML page. One way you can do this is to set up links in HTML that actually trigger calls to JavaScript functions when the link is clicked.
There are two ways to do this:
1. Use the onClick attribute of the a tag to call the function:
<a href=”#” onClick=”functionName()”>Link text</a>
2. Use a javascript: URL in the href attribute of the a tag to call
the function:
<a href=”javascript:functionName()”>Link text</a>
The following task illustrates these two methods of calling a function from a link by creating a function that displays an alert dialog box to the user and then providing two separate links for the user to use to call the function:
1. Open a new HTML document in your preferred HTML or text editor.
2. Create the header of the document with opening and closing head tags:
<head>
</head>
3. Insert a script block in the header of the document:
<script language=”JavaScript”>
<!--
// -->
</script>
4. Create a function named hello that takes no arguments:
function hello() {
}
5. In the function, use the window.alert method to display an alert
dialog box:
window.alert(“Hello”);
6. Create the body of the document with opening and closing body tags.
7. In the final page create two links that call the hello function using
onClick and the javascript: URL techniques so that the final
page looks like Listing 31-1.
<head>
<script language=”JavaScript”>
<!--
function hello() {
window.alert(“Hello”);
}
// -->
</script>
</head>
<body>
<a href=”#” onClick=”hello()
相关文档:
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......
SCRIPT 标记
用于包含JavaScript代码.
属性
LANGUAGE 定义脚本语言
SRC 定义一个
URL用以指定以.JS结尾的文件
window对象
每个HTML文档的顶层对象.
属性
frames[] 子桢数组.每个子桢数组按源文档中定义的顺序存
放.
f ......
<html>
<body>
<style>
ul,li{margin: 0; padding: 0;width:100%;}
</style>
<script language="javascript" type="text/javascript">
function checkword()
{
var wordvalue=document.getElementById("word").value.toLowerCase();
var alltxt="管理员| ......
1.大家在实际工作中,会写各式各样的赋值语句。
比如最常用的obj.style.display = "none";
如果这样的赋值语句一多,obj.style一排下来都要看晕了
下面我的base.js中的extend函数可以允许用json格式赋值属性甚至是函数句柄
/**
* 扩展函数
* @param target 需要扩展的对象
* @para ......
今天在补习javascript中。遇到几个相对陌生的运算符,特别在此写下来。
1、三元运算符?:,这是js中唯一一个三元运算符(这和C#中的一样),用法如下
var x=1;
var y=3;
(x>y)?(x-y):(y-x);
2、typeof运算符
typeof 是一个一元运算,放在一个运算数之前,运算数可以是任意类型。 ......