html.css.javascript简单教程和示例

首先推荐一个网站 http://www.w3school.com.cn/

(1)css和html

html的架构是由元素组成的,元素由起始标签和终止标签和元素内容组成。元素内容可以为空。

标签可以拥有属性,如下

 

<a href="http://www.w3school.com.cn">This is a link</a>
下面的语句表示一个内联框架
<iframe src="www.ucas.ac.cn" width="200" height="200"></iframe>

最简单的网站如下

 

<html>
<body>
<p>hello,word!</p>
</body>
</html>

如果我们在网页上设置一个可提交的表单,就有如下代码

<html>
<body>
<p>hello,world!</p>
<form>
First name:
<input type="text" name="firstname" />
<br />
Last name:
<input type="text" name="lastname" />
</form>

</body>
</html>

下一节我们将详细讲述其应用。

对于样式,就是对属性的规定,有如下原则

 

  1. 浏览器缺省设置
  2. 外部样式表
  3. 内部样式表(位于 <head> 标签内部)
  4. 内联样式(在 HTML 元素内部)

样式表的基本语法是

 

 

selector {declaration1; declaration2; ... declarationN }

 

例子如下:

 

h1 {color:red; font-size:14px;}

下面是使用内部样式表的例子

 

<html>
<head>
<style type="text/css">
p {background-color: rgb(250,0,255)}
</style>

</head>
<body>
<p>hello,world!</p>
<form>
First name:
<input type="text" name="firstname" />
<br />
Last name:
<input type="text" name="lastname" />
</form>
</body>
</html>

如果要使用外部样式表,写作如下就可以了

 

<style type="text/css" href="b.css" />

 

(2)javascript用法

下面是最简单的带javascript脚本的网页

<html>

<head>
<style type="text/css">
</style>
</head>

<body>
<form>
First name:
<input type="text" name="firstname" />
<br />
Last name:
<input type="text" name="lastname" />
</form>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>

如果要使用外部脚本,只要写如下代码即可

<script src="/js/example_externaljs.js"></script>

我们来看下面的代码

<html>
<head>
<script type="text/javascript">

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(email,"Email must be filled out!")==false)
    {email.focus();return false}
  }
}
</script>
</head>

<body>
<form action="submitpage.htm" οnsubmit="return validate_form(this)" method="post">
Email: <input type="text" name="email" size="30">
<input type="submit" value="Submit">
</form>
</body>

</html>

action后面的内容标识向何处提交表单,他可以是下面两种:

绝对 URL - 指向其他站点(比如 src="www.example.com/example.htm")

相对 URL - 指向站点内的文件(比如 src="example.htm")

onsubmit应该指向一个函数,系统讲根据该函数返回值决定是否提交表单。

method有get和post两种选择,区别可以详见http://www.cnblogs.com/hnrainll/archive/2011/06/07/2074593.html

主要记住,post是通过url请求来传递数据的,例如进行get后,返回的页面网址为

http://www.w3school.com.cn/example/html/form_action.asp?fname=cdcdc&lname=ssss

其中的cdcdc和ssss就是我们在表单中所提交的数据。

 <input type="text" name="email" size="30">
<input type="submit" value="Submit">

对于input标签,type标识类型,text就是文本。submit则是提交按钮。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值