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. JS Json数据转换

    *** json字符串中不能出现单引号,不然JSON.parse会报错,处理方式将单引号转义 概述 JSON.stringify() 方法可以将任意的 JavaScript 值序列化成 JSON 字符 ...

  2. Delphi 获取临时数据集 ClientDataSet

    function GetcdsAccountsData: OleVariant; var ASQLQuery: TSQLQuery; Adsp: TProvider; begin ASQLQuery: ...

  3. SDRAM的主要参数

    (1) 容量.SDRAM的容量经常用XX存储单元×X体×每个存储单元的位数来表示.例如某SDRAM芯片的容量为4M×4×8bit,表明该存储器芯片的容量为16 M字节.或128 M bit. (2) ...

  4. JQuery 常用

    1.同一name分组的多个radio,获取选中radio的value值: var check_val=$("input[name='属性名']:checked").val(); 2 ...

  5. npm -v 一直闪

    一直闪一般是配置搞错了 参考: windows安装完nodejs后做了相关环境变量配置后,cmd输入npm没反应啊 就光标一直闪 node是正常的 或者 https://segmentfault.co ...

  6. MySQL中auto_increment的基本特性

    创建数据表时,经常会出现auto_increment这个词,下面就来了解一下它吧. MySQL的中AUTO_INCREMENT类型的属性用于为一个表中记录自动生成ID功能,可在一定程度上代替Oracl ...

  7. [字符编码]Invalid byte 1 of 1-byte UTF-8 sequence终极解决方案

    今天在eclipse中编写pom.xml文件时,注释中的中文被eclipse识别到错误:Invalid byte 1 of 1-byte UTF-8 sequence,曾多次遇到该问题,问题的根源是: ...

  8. [OC笔记]我的第一个OC程序

    这是我第一个OC程序,详情都写在了注释里面,讲的是Student和Book这两个类的创建和使用.(是不是觉得student这个类在各种语言入门代码里经常出现呢?真实有爱) 看完这些,你会发现,咱们其实 ...

  9. 无法更新 EntitySet“SoreInfo_Table”,因为它有一个 DefiningQuery,而 <ModificationFunctionMapping> 元素中没有支持当前操作的 <InsertFunction> 元素。

    无法更新 EntitySet"SoreInfo_Table",因为它有一个 DefiningQuery,而 <ModificationFunctionMapping> ...

  10. MySQL 数据库常用命令

    1.MySQL常用命令 create database name; 创建数据库 use databasename; 选择数据库 drop database name 直接删除数据库,不提醒 show ...