http://www.fgm.cc/learn/

First class ,6 examples anlaysisi

 <!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Change Attribute?</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
padding:0;
margin:0;
}
#changeAttr{
width:370px;
/*width:auto or 100%, not center*/
margin:100px auto;
border:1px solid #000000;
padding:50px; }
#obj{
width:150px;
margin:20px auto;
height:150px;
background-color:black;
}
</style>
</head>
<body>
<div id='changeAttr'>
<h1>Change Attribute</h1>
<div id='content'>
<input id='chWidth' type='button' value='CH WIDTH'/>
<input id='chHeight' type='button' value='CH HIGHT'/>
<input id='chColor' type='button' value='CH COLOR'/>
<input id='chHide' type='button' value='CH HIDE'/>
<input id='chReset' type='button' value='CH RESET'/>
<div id='obj'></div>
</div>
</div>
<script>
// window.onload = function(){
// var chWidth = document.getElementById("chWidth");
// var chHeight = document.getElementById("chHeight");
// var chColor = document.getElementById("chColor");
// var chHide = document.getElementById("chHide");
// var chReset = document.getElementById("chReset");
// var obj = document.getElementById("obj");
//
// chWidth.onclick = function(){
// obj.style.width = '300px';
// }
// chHeight.onclick = function(){
// obj.style.height = '300px';
// }
// chColor.onclick = function(){
// obj.style.backgroundColor = '#ff0000';
// }
// chHide.onclick = function(){
// obj.style.display = 'none';
// }
// chReset.onclick = function(){
// obj.style.width = '150px';
// obj.style.height = '150px';
// obj.style.backgroundColor = '#000000';
// obj.style.display = 'block';
// }
// } // var changeStyle = function (elem, attr, value)
// {
// elem.style[attr] = value
// };
// window.onload = function ()
// {
// var oBtn = document.getElementsByTagName("input");
// var oDiv = document.getElementById("obj");
// var oAtt = ["width","height","background","display","display"];
// var oVal = ["200px","200px","red","none","block"];
//
// for (var i = 0; i < oBtn.length; i++)
// {
// oBtn[i].index = i;
// oBtn[i].onclick = function ()
// {
// this.index == oBtn.length - 1 && (oDiv.style.cssText = "");
// console.log(this.index);
// changeStyle(oDiv, oAtt[this.index], oVal[this.index])
// }
// }
// }; var changeStyle = function(ele,attr,val){
ele.style[attr] = val;
};
window.onload = function(){
var oBtn = document.getElementsByTagName("input");
var oDiv = document.getElementById("obj");
var oAttr = ["width","height","backgroundColor","display","display"];
var oVal = ["200px","200px","red","none","block"]; for(var i=0;i<oBtn.length;i++){
oBtn[i].index = i;
oBtn[i].onclick = function(){ this.index == oBtn.length - 1 && (oDiv.style.cssText = "");
//console.log(this.index);
changeStyle(oDiv,oAttr[this.index],oVal[this.index]);
};
}
} </script>
</body>
</html>

1.width auto or 100%, not center;

2.good at using for ,like getElementsByTagName('input');

3.this.index == oBtn.length - 1 && (oDiv.style.cssText = ""); like

  if(a >=5){
  alert("你好");
  }
  可以写成:
  a >= 5 && alert("你好");

4. look at 3,oDiv.style.cssText = "",all recover,it means add style through js,then the style go to html lines, when you clean style,you just clean style inline,not the style in<style> or stylesheet.

1.首次打开页面时候便已有默认风格
  不好:在全局里面设置一次风格,然后在onclick里面在写一遍同样的代码
  改进:在<style>先给风格,只是以后点击会更换风格,减少代码量

2.border:横排 有重复边
  不好:给每个子元素每边都加,然后统一去掉右边框,最好给父元素或最后一个子加一个右边框
  改进:父每边都有,子统一有右边框,最后去掉最后子的右边框;来回折腾的减少
3.<li>red</li> 加text-indent:-9999px;方便理解

4.去掉外层div ,当里面li:float:left时,ul仍然可以包住li
5.<a href="javascript:;"></a>

1. input 前必须加#content,否则margin-bottom会被#content中的margin覆盖,(优先级不够),by the way,有padding好看多了

#################################################################################

1.text-align:center,对div:block不管用,对inline-block管用
2.子元素float之后,父{width:xxxpx;margin:0 auto;},此时虽然没有包住子,但子依然居中;父加上height,就包住子

#########################################################################

First class ,6 examples anlaysisi的更多相关文章

  1. Js: Extensible Calendar Examples

    http://ext.ensible.comhttps://github.com/bmoeskau/Extensiblehttps://github.com/TeamupCom/extensibleh ...

  2. Selenium Xpath Tutorials - Identifying xpath for element with examples to use in selenium

    Xpath in selenium is close to must required. XPath is element locator and you need to provide xpath ...

  3. https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/

        https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ ...

  4. (转载)SQL Reporting Services (Expression Examples)

    https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...

  5. Examples of MIB Variables - SNMP Tutorial

    30.5 Examples of MIB Variables Versions 1 and 2 of SNMP each collected variables together in a singl ...

  6. DataBinding examples

    Databinding in Windows Forms demo (CSWinFormDataBinding) /************************************* Modu ...

  7. https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

    https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

  8. Bootstrap Table Examples

    The examples of bootstrap table http://bootstrap-table.wenzhixin.net.cn/examples/ http://www.jq22.co ...

  9. RSpec shared examples with template methods

    It’s pretty common to have multiple tests that are nearly the same. In one app, we support bidding o ...

随机推荐

  1. python基础知识4——collection类——计数器,有序字典,默认字典,可命名元组,双向队列

    1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能  Counter 我们从中挑选一些相对常用的方法来举例: 在上面的例子 ...

  2. Badboy录制脚本参数化

    Jmeter录制脚本多采用Badboy工具 简单参数修改 第一步,先录制场景: a.开始录制,打开浏览器www.sogou.com b.在输入框中输入文字“Badboy" c.回车,关闭录制 ...

  3. Begin :SWIFT 基本语法

    国内介绍IOS书籍大多是很陈旧的代码, 2014年Apple发布了Swift语言, 毫无疑问Swift是一个强大的语言, 但是纵观国内的IOS现状,大家大多已经习惯了了OC, OC能解决的问题谁会想到 ...

  4. eclipse或者myeclipse安装svn报错”unable to load default svn client”

    是svn版本低了的问题 subeclipse下载,直接百度site1.X                  X为你需要的版本 解压site1.X 将此窗口先放到一边 在eclipse的安装目录下的dr ...

  5. 全是套路——BFS

    #include <iostream> #include <vector> #include <string> #include <vector> #i ...

  6. requireJS的引用

    main.js: require.config({ paths: { jquery: 'jquery-1.7.2', biz: 'biz', }}); require(['jquery', 'biz' ...

  7. 如何向新手程序员介绍Java编程

    学习Java,他们都说很easy. 作为一名刚从斯康星大学麦迪逊分校计算机科学系毕业的大学生,我通过一些编程课程认识了很多使用Java的朋友.现在很多学校都在从别的编程语言(大多是C ++)转教Jav ...

  8. C# 开源压缩组件比较

    SevenZipSharp check()为检查压缩包,有BUG,360创建的zip压缩包有无密码,密码错对都返回true DotNetZip 提供的函数比较人性化,缺点是只支持zip SharpCo ...

  9. 谈谈Activiti中流程对象之间的关系

    详细见:http://www.kafeitu.me/activiti/2012/03/22/workflow-activiti-action.html (咖啡兔好牛!) 详细见: http://blo ...

  10. swift 之 闭包

    一.闭包 格式:{  (  参数名:类型, 参数名:类型 ..  )   in 内容体  return  返回值   }  最完整的闭包 1.省略参数类型 {  (  参数名, 参数名..  )   ...