PHP常用知识点记录

<div style="text-align: left;"><span style="font-weight: bold; font-size: 18px; font-family: Arial, Helvetica, sans-serif;"> /*字符串大小写字符转换*/</span></div>
<span style="font-size: 18px;"><strong>1    strtolower()       //将字符串转换为小写形式</strong></span>
<span style="font-size: 18px;"><strong>2    strtoupper()     //将字符串转换为大写形式</strong></span>
<span style="font-size: 18px;"><strong>3    ucfirst()           //将字符串的第一个字符转换为大写形式</strong></span>
<span style="font-size: 18px;"><strong>4    ucwords()       //将字符串中每一个单词的首字母转换为大写形式</strong></span>
<span style="font-size: 18px;"><strong>-------------------------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>/*字符串查找函数*/</strong></span>
<span style="font-size: 18px;"><strong>一、strstr — 查找字符串的首次出现 </strong></span>
<span style="font-size: 18px;"><strong>二、stristr strstr不区分大小写的版本 </strong></span>
<span style="font-size: 18px;"><strong>三、strpos -查找字符串首次出现的位置 </strong></span>
<span style="font-size: 18px;"><strong>四、substr -返回字符串的子串 </strong></span>
<span style="font-size: 18px;"><strong>五、strrchr -查找指定字符在字符串中的最后一次出现 </strong></span>
<span style="font-size: 18px;"><strong>六、strripos -计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写) </strong></span>
<span style="font-size: 18px;"><strong>七、stripos -查找字符串首次出现的位置(不区分大小定) </strong></span>
<span style="font-size: 18px;"><strong>八、strrpos -计算指定字符串在目标字符串中最后一次出现的位置</strong></span>
<span style="font-size: 18px;"><strong>substr_count — 计算字串出现的次数 </strong></span>
<span style="font-size: 18px;"><strong>------------------------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>/*用php自带函数去除html标记*/</strong></span>
<span style="font-size: 18px;"><strong>strip_tags       去掉 HTML 及 PHP 的标记。</strong></span>
<span style="font-size: 18px;"><strong>语法: string strip_tags(string str);</strong></span>
<span style="font-size: 18px;"><strong>传回值: 字串</strong></span>
<span style="font-size: 18px;"><strong>函式种类: 资料处理</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>string str_shuffle ( string $str )</strong></span>
<span style="font-size: 18px;"><strong>str_shuffle() 函数打乱一个字符串,使用任何一种可能的排序方案。</strong></span>
<span style="font-size: 18px;"><strong>-----------------------------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>PHP 数组排序方法总结</strong></span>
<span style="font-size: 18px;"><strong>文章详细的介绍了快速创建数组的函数range()和常见PHP数组排序的方法,希望对大家有帮助。</strong></span>
<span style="font-size: 18px;"><strong>随着PHP的快速发展,用它的人越来越多,在PHP数组学习摘录部分了解到最基本的PHP数组的建立和数组元素的显示。需要深入学习下PHP数组的相关操作。首先接触的就是PHP数组排序、降序的排序问题。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>sort:本函数为 array 中的单元赋予新的键名。这将删除原有的键名而不仅是重新排序。 </strong></span>
<span style="font-size: 18px;"><strong>rsort:本函数对数组进行逆向排序(最高到最低)。 删除原有的键名而不仅是重新排序。 </strong></span>
<span style="font-size: 18px;"><strong>asort:对数组进行排序并保持索引关系 </strong></span>
<span style="font-size: 18px;"><strong>arsort:对数组进行逆向排序并保持索引关系 </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>ksort:对数组按照键名排序,保留键名到数据的关联 </strong></span>
<span style="font-size: 18px;"><strong>krsort:对数组按照键名逆向排序,保留键名到数据的关联 </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>natsort:对字母数字字符串进行排序并保持原有键/值的关联 </strong></span>
<span style="font-size: 18px;"><strong>natcasesort:同natsort排序算法,但不区分大小写字母排序 </strong></span>
<span style="font-size: 18px;"><strong>str_shuffle — 随机打乱一个字符串 </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>-------------------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>一、数组操作的基本函数</strong></span>
<span style="font-size: 18px;"><strong>数组的键名和值</strong></span>
<span style="font-size: 18px;"><strong>array_values($arr);  获得数组的值</strong></span>
<span style="font-size: 18px;"><strong>array_keys($arr);  获得数组的键名</strong></span>
<span style="font-size: 18px;"><strong>array_flip($arr);  数组中的值与键名互换(如果有重复前面的会被后面的覆盖)</strong></span>
<span style="font-size: 18px;"><strong>in_array("apple",$arr);  在数组中检索apple</strong></span>
<span style="font-size: 18px;"><strong>array_search("apple",$arr);  在数组中检索apple ,如果存在返回键名</strong></span>
<span style="font-size: 18px;"><strong>array_key_exists("apple",$arr);  检索给定的键名是否存在数组中</strong></span>
<span style="font-size: 18px;"><strong>isset($arr[apple]):   检索给定的键名是否存在数组中</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>数组的内部指针</strong></span>
<span style="font-size: 18px;"><strong>current($arr);  返回数组中的当前单元</strong></span>
<span style="font-size: 18px;"><strong>pos($arr);  返回数组中的当前单元</strong></span>
<span style="font-size: 18px;"><strong>key($arr);  返回数组中当前单元的键名</strong></span>
<span style="font-size: 18px;"><strong>prev($arr);  将数组中的内部指针倒回一位</strong></span>
<span style="font-size: 18px;"><strong>next($arr);  将数组中的内部指针向前移动一位</strong></span>
<span style="font-size: 18px;"><strong>end($arr);  将数组中的内部指针指向最后一个单元</strong></span>
<span style="font-size: 18px;"><strong>reset($arr;  将数组中的内部指针指向第一个单元</strong></span>
<span style="font-size: 18px;"><strong>each($arr);  将返回数组当前元素的一个键名/值的构造数组,并使数组指针向前移动一位</strong></span>
<span style="font-size: 18px;"><strong>list($key,$value)=each($arr);  获得数组当前元素的键名和值</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>数组和变量之间的转换</strong></span>
<span style="font-size: 18px;"><strong>extract($arr);用于把数组中的元素转换成变量导入到当前文件中,键名当作变量名,值作为变量值</strong></span>
<span style="font-size: 18px;"><strong>注:(第二个参数很重要,可以看手册使用)使用方法 echo $a;</strong></span>
<span style="font-size: 18px;"><strong>compact(var1,var2,var3);用给定的变量名创建一个数组</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>二、数组的分段和填充</strong></span>
<span style="font-size: 18px;"><strong>数组的分段</strong></span>
<span style="font-size: 18px;"><strong>array_slice($arr,0,3);  可以将数组中的一段取出,此函数忽略键名</strong></span>
<span style="font-size: 18px;"><strong>array_splice($arr,0,3,array("black","maroon"));  可以将数组中的一段取出,与上个函数不同在于返回的序列从原数组中删除</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>分割多个数组</strong></span>
<span style="font-size: 18px;"><strong>array_chunk($arr,3,TRUE);  可以将一个数组分割成多个,TRUE为保留原数组的键名</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>数组的填充</strong></span>
<span style="font-size: 18px;"><strong>array_pad($arr,5,'x');  将一个数组填补到制定长度</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>三、数组与栈</strong></span>
<span style="font-size: 18px;"><strong>array_push($arr,"apple","pear");  将一个或多个元素压入数组栈的末尾(入栈),返回入栈元素的个数</strong></span>
<span style="font-size: 18px;"><strong>array_pop($arr);  将数组栈的最后一个元素弹出(出栈)</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>四、数组与列队</strong></span>
<span style="font-size: 18px;"><strong>array_shift($arr);数组中的第一个元素移出并作为结果返回(数组长度减1,其他元素向前移动一位,数字键名改为从零技术,文字键名不变)</strong></span>
<span style="font-size: 18px;"><strong>array_unshift($arr,"a",array(1,2));在数组的开头插入一个或多个元素</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>五、回调函数</strong></span>
<span style="font-size: 18px;"><strong>array_walk($arr,'function','words');  使用用户函数对数组中的每个成员进行处理(第三个参数传递给回调函数function)</strong></span>
<span style="font-size: 18px;"><strong>array_mpa("function",$arr1,$arr2);  可以处理多个数组(当使用两个或更多数组时,他们的长度应该相同)</strong></span>
<span style="font-size: 18px;"><strong>array_filter($arr,"function");  使用回调函数过滤数组中的每个元素,如果回调函数为TRUE,数组的当前元素会被包含在返回的结果数组中,数组的键名保留不变</strong></span>
<span style="font-size: 18px;"><strong>array_reduce($arr,"function","*");  转化为单值函数(*为数组的第一个值)</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>六、数组的排序</strong></span>
<span style="font-size: 18px;"><strong>通过元素值对数组排序</strong></span>
<span style="font-size: 18px;"><strong>sort($arr);  由小到大的顺序排序(第二个参数为按什么方式排序)忽略键名的数组排序</strong></span>
<span style="font-size: 18px;"><strong>rsort($arr);  由大到小的顺序排序(第二个参数为按什么方式排序)忽略键名的数组排序</strong></span>
<span style="font-size: 18px;"><strong>usort($arr,"function");  使用用户自定义的比较函数对数组中的值进行排序(function中有两个参数,0表示相等,正数表示第一个大于第二个,负数表示第一个小于第二个)忽略键名的数组排序</strong></span>
<span style="font-size: 18px;"><strong>asort($arr);  由小到大的顺序排序(第二个参数为按什么方式排序)保留键名的数组排序</strong></span>
<span style="font-size: 18px;"><strong>arsort($arr);  由大到小的顺序排序(第二个参数为按什么方式排序)保留键名的数组排序</strong></span>
<span style="font-size: 18px;"><strong>uasort($arr,"function");  使用用户自定义的比较函数对数组中的值进行排序(function中有两个参数,0表示相等,正数表示第一个大于第二个,负数表示第一个小于第二个)保留键名的数组排序</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>通过键名对数组排序</strong></span>
<span style="font-size: 18px;"><strong>ksort($arr);  按照键名正序排序</strong></span>
<span style="font-size: 18px;"><strong>krsort($arr);  按照键名逆序排序</strong></span>
<span style="font-size: 18px;"><strong>uksort($arr,"function");  使用用户自定义的比较函数对数组中的键名进行排序(function中有两个参数,0表示相等,正数表示第一个大于第二个,负数表示第一个小于第二个)</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>自然排序法排序</strong></span>
<span style="font-size: 18px;"><strong>natsort($arr);  自然排序(忽略键名)</strong></span>
<span style="font-size: 18px;"><strong>natcasesort($arr);  自然排序(忽略大小写,忽略键名)</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>七、数组的计算</strong></span>
<span style="font-size: 18px;"><strong>数组元素的求和</strong></span>
<span style="font-size: 18px;"><strong>array_sum($arr);  对数组内部的所有元素做求和运算</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>数组的合并</strong></span>
<span style="font-size: 18px;"><strong>array_merge($arr1,$arr2);  合并两个或多个数组(相同的字符串键名,后面的覆盖前面的,相同的数字键名,后面的不会做覆盖操作,而是附加到后面)</strong></span>
<span style="font-size: 18px;"><strong>“+”$arr1+$arr2;  对于相同的键名只保留后一个</strong></span>
<span style="font-size: 18px;"><strong>array_merge_recursive($arr1,$arr2);   递归合并操作,如果数组中有相同的字符串键名,这些值将被合并到一个数组中去。如果一个值本身是一个数组,将按照相应的键名把它合并为另一个数组。当数组 具有相同的数组键名时,后一个值将不会覆盖原来的值,而是附加到后面</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>数组的差集</strong></span>
<span style="font-size: 18px;"><strong>array_diff($arr1,$arr2);  返回差集结果数组</strong></span>
<span style="font-size: 18px;"><strong>array_diff_assoc($arr1,$arr2,$arr3);  返回差集结果数组,键名也做比较</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>数组的交集</strong></span>
<span style="font-size: 18px;"><strong>array_intersect($arr1,$arr2);  返回交集结果数组</strong></span>
<span style="font-size: 18px;"><strong>array_intersect_assoc($arr1,$arr2);  返回交集结果数组,键名也做比较</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>八、其他的数组函数</strong></span>
<span style="font-size: 18px;"><strong>range(0,12);  创建一个包含指定范围单元的数组</strong></span>
<span style="font-size: 18px;"><strong>array_unique($arr);  移除数组中重复的值,新的数组中会保留原始的键名</strong></span>
<span style="font-size: 18px;"><strong>array_reverse($arr,TRUE);  返回一个单元顺序与原数组相反的数组,如果第二个参数为TRUE保留原来的键名</strong></span>
<span style="font-size: 18px;"><strong>//srand((float)microtime()*10000000);   随机种子触发器</strong></span>
<span style="font-size: 18px;"><strong>array_rand($arr,2);  从数组中随机取出一个或 多个元素</strong></span>
<span style="font-size: 18px;"><strong>shuffle($arr);  将数组的顺序打乱</strong></span>
<span style="font-size: 18px;"><strong> </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>PHP的数据类型转换属于强制转换,允许转换的PHP数据类型有:</strong></span>
<span style="font-size: 18px;"><strong>(int)、(integer):转换成整形</strong></span>
<span style="font-size: 18px;"><strong>(float)、(double)、(real):转换成浮点型</strong></span>
<span style="font-size: 18px;"><strong>(string):转换成字符串</strong></span>
<span style="font-size: 18px;"><strong>(bool)、(boolean):转换成布尔类型</strong></span>
<span style="font-size: 18px;"><strong>(array):转换成数组</strong></span>
<span style="font-size: 18px;"><strong>(object):转换成对象</strong></span>
<span style="font-size: 18px;"><strong>PHP数据类型有三种转换方式:</strong></span>
<span style="font-size: 18px;"><strong>在要转换的变量之前加上用括号括起来的目标类型</strong></span>
<span style="font-size: 18px;"><strong>使用3个具体类型的转换函数,intval()、floatval()、strval()</strong></span>
<span style="font-size: 18px;"><strong>使用通用类型转换函数settype(mixed var,string type)</strong></span>
<span style="font-size: 18px;"><strong> 第一种转换方式: (int)  (bool)  (float)  (string)  (array) (object)</strong></span>
<span style="font-size: 18px;"><strong> </strong></span>
<span style="font-size: 18px;"><strong><?php   </strong></span>
<span style="font-size: 18px;"><strong>$num1=3.14;   </strong></span>
<span style="font-size: 18px;"><strong>$num2=(int)$num1;   </strong></span>
<span style="font-size: 18px;"><strong>var_dump($num1); //输出float(3.14)   </strong></span>
<span style="font-size: 18px;"><strong>var_dump($num2); //输出int(3)   </strong></span>
<span style="font-size: 18px;"><strong>?>  </strong></span>
<span style="font-size: 18px;"><strong>第二种转换方式:  intval()  floatval()  strval()</strong></span>
<span style="font-size: 18px;"><strong> </strong></span>
<span style="font-size: 18px;"><strong><?php   </strong></span>
<span style="font-size: 18px;"><strong>$str="123.9abc";   </strong></span>
<span style="font-size: 18px;"><strong>$int=intval($str);     //转换后数值:123   </strong></span>
<span style="font-size: 18px;"><strong>$float=floatval($str); //转换后数值:123.9   </strong></span>
<span style="font-size: 18px;"><strong>$str=strval($float);   //转换后字符串:"123.9"    </strong></span>
<span style="font-size: 18px;"><strong>?>  </strong></span>
<span style="font-size: 18px;"><strong>第三种转换方式:  settype();</strong></span>
<span style="font-size: 18px;"><strong> </strong></span>
<span style="font-size: 18px;"><strong><?php   </strong></span>
<span style="font-size: 18px;"><strong>$num4=12.8;   </strong></span>
<span style="font-size: 18px;"><strong>$flg=settype($num4,"int");   </strong></span>
<span style="font-size: 18px;"><strong>var_dump($flg);  //输出bool(true)   </strong></span>
<span style="font-size: 18px;"><strong>var_dump($num4); //输出int(12)   </strong></span>
<span style="font-size: 18px;"><strong>?></strong></span>
<span style="font-size: 18px;"><strong>-------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>date_default_timezone_set('PRC'); //默认时区 </strong></span>
<span style="font-size: 18px;"><strong>echo "今天:",date("Y-m-d",time()),"<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; </strong></span>
<span style="font-size: 18px;"><strong>echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>"; </strong></span>
<span style="font-size: 18px;"><strong>?></strong></span>
<span style="font-size: 18px;"><strong><?php </strong></span>
<span style="font-size: 18px;"><strong>echo (strtotime('2020-5-20′)-strtotime(date(“Y-m-d”)))/86400;? </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>echo date('Y-m-t'); //获取当前月的最后一天</strong></span>
<span style="font-size: 18px;"><strong>echo date('Y-m-t',strtotime("09.13.1987")); //获取指定月份的最后一天</strong></span>
<span style="font-size: 18px;"><strong>//获取指定日期的上个月的最后一天</strong></span>
<span style="font-size: 18px;"><strong>$curtime="1987-09-13";</strong></span>
<span style="font-size: 18px;"><strong>$time=strtotime($curtime );</strong></span>
<span style="font-size: 18px;"><strong>date('Y-m-t',strtotime('last month',$time));</strong></span>
<span style="font-size: 18px;"><strong>//获取指定日期的下个月的最后一天</strong></span>
<span style="font-size: 18px;"><strong>$curtime="2010-04-11";</strong></span>
<span style="font-size: 18px;"><strong>$time=strtotime($curtime );</strong></span>
<span style="font-size: 18px;"><strong>date('Y-m-t',strtotime('next month',$time));</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>===========================================================================================</strong></span>
<span style="font-size: 18px;"><strong>图片上传代码</strong></span>
<span style="font-size: 18px;"><strong> <form name="form1" method="post" enctype="multipart/form- data" action="requestfile/asprece.aspx"></strong></span>
<span style="font-size: 18px;"><strong>//如果file框没有加runat="server",则 form里一定要加上 enctype="multipart/form-data"这样才可以实现上传文件到服务器;</strong></span>
<span style="font-size: 18px;"><strong>----------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>让input表单只读的几种方法:</strong></span>
<span style="font-size: 18px;"><strong>如使<input type="text" name="input1" value="建站学"> 的内容,建站学 两个字不可以修改。</strong></span>
<span style="font-size: 18px;"><strong>方法1: οnfοcus=this.blur()</strong></span>
<span style="font-size: 18px;"><strong><input type="text" name="input1" value="建站学" οnfοcus=this.blur()></strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>方法2: readonly</strong></span>
<span style="font-size: 18px;"><strong><input type="text" name="input1" value="建站学" readonly></strong></span>
<span style="font-size: 18px;"><strong><input type="text" name="input1" value="建站学" readonly="true"></strong></span>
<span style="font-size: 18px;"><strong>方法3: disabled</strong></span>
<span style="font-size: 18px;"><strong><input type="text" name="input1" value="建站学" disabled> </strong></span>
<span style="font-size: 18px;"><strong>===========================================================================================</strong></span>
<span style="font-size: 18px;"><strong><script> </strong></span>
<span style="font-size: 18px;"><strong>/*</strong></span>
<span style="font-size: 18px;"><strong>	* 功能:图片上传前预览</strong></span>
<span style="font-size: 18px;"><strong>	* 方法名:setImagePreview()</strong></span>
<span style="font-size: 18px;"><strong>	* 注意点:input表单中id = doc  img中id=preview</strong></span>
<span style="font-size: 18px;"><strong>*/</strong></span>
<span style="font-size: 18px;"><strong>function setImagePreview() { </strong></span>
<span style="font-size: 18px;"><strong>        var docObj=document.getElementById("doc"); </strong></span>
<span style="font-size: 18px;"><strong>        var imgObjPreview=document.getElementById("preview"); </strong></span>
<span style="font-size: 18px;"><strong>                if(docObj.files &&    docObj.files[0]){ </strong></span>
<span style="font-size: 18px;"><strong>                        //火狐下,直接设img属性 </strong></span>
<span style="font-size: 18px;"><strong>                        imgObjPreview.style.display = 'inline'; </strong></span>
<span style="font-size: 18px;"><strong>                        imgObjPreview.style.width = '50px'; </strong></span>
<span style="font-size: 18px;"><strong>                        imgObjPreview.style.height = '25px';                    </strong></span>
<span style="font-size: 18px;"><strong>                        //imgObjPreview.src = docObj.files[0].getAsDataURL(); </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>      //火狐7以上版本不能用上面的getAsDataURL()方式获取,需要一下方式  </strong></span>
<span style="font-size: 18px;"><strong>      imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]); </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>                }else{ </strong></span>
<span style="font-size: 18px;"><strong>                        //IE下,使用滤镜 </strong></span>
<span style="font-size: 18px;"><strong>                        docObj.select(); </strong></span>
<span style="font-size: 18px;"><strong>                        var imgSrc = document.selection.createRange().text; </strong></span>
<span style="font-size: 18px;"><strong>                        var localImagId = document.getElementById("localImag"); </strong></span>
<span style="font-size: 18px;"><strong>                        //必须设置初始大小 </strong></span>
<span style="font-size: 18px;"><strong>                        localImagId.style.width = "50px"; </strong></span>
<span style="font-size: 18px;"><strong>                        localImagId.style.height = "25px"; </strong></span>
<span style="font-size: 18px;"><strong>                        //图片异常的捕捉,防止用户修改后缀来伪造图片 </strong></span>
<span style="font-size: 18px;"><strong>try{ </strong></span>
<span style="font-size: 18px;"><strong>                                localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)"; </strong></span>
<span style="font-size: 18px;"><strong>                                localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc; </strong></span>
<span style="font-size: 18px;"><strong>                        }catch(e){ </strong></span>
<span style="font-size: 18px;"><strong>                                alert("您上传的图片格式不正确,请重新选择!"); </strong></span>
<span style="font-size: 18px;"><strong>                                return false; </strong></span>
<span style="font-size: 18px;"><strong>                        } </strong></span>
<span style="font-size: 18px;"><strong>                        imgObjPreview.style.display = 'none'; </strong></span>
<span style="font-size: 18px;"><strong>                        document.selection.empty(); </strong></span>
<span style="font-size: 18px;"><strong>                } </strong></span>
<span style="font-size: 18px;"><strong>                return true; </strong></span>
<span style="font-size: 18px;"><strong>        } </strong></span>
<span style="font-size: 18px;"><strong></script> </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>----------------------------------------------------------------------------------------------------------------</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>	/*</strong></span>
<span style="font-size: 18px;"><strong>		* 作用:本方法是随着屏幕的大小改变而改变</strong></span>
<span style="font-size: 18px;"><strong>		* 参数:无</strong></span>
<span style="font-size: 18px;"><strong>		* 其它:在此方法里面可以写方法</strong></span>
<span style="font-size: 18px;"><strong>	*/</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>	$(window).resize(function(){</strong></span>
<span style="font-size: 18px;"><strong>		$('.totalbig').css({</strong></span>
<span style="font-size: 18px;"><strong>			'width':($('body').width()-2)+'px',</strong></span>
<span style="font-size: 18px;"><strong>			'height':$('body').height()</strong></span>
<span style="font-size: 18px;"><strong>		})</strong></span>
<span style="font-size: 18px;"><strong>		$('.content_right').css({</strong></span>
<span style="font-size: 18px;"><strong>			'width':($('body').width()-192)+'px'</strong></span>
<span style="font-size: 18px;"><strong>		})</strong></span>
<span style="font-size: 18px;"><strong>	});</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>============================================================================================</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>用js实现简单的点击返回顶部效果</strong></span>
<span style="font-size: 18px;"><strong>当页面特别长的时候,用户想回到页面顶部,必须得滚动好几次滚动键才能回到顶部,如果在页面右下角有个“返回顶部”的按钮,用户点击一下,就可以回到顶部,对于用户来说,是一个比较好的体验。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>实现原理:当页面加载的时候,把元素定位到页面的右下角,当页面滚动时,元素一直位于右下角,当用户点击的时候,页面回到顶部。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>要点一:document.documentElement.clientWidth || document.body.clientWidth; 获得可视区的宽度。后面是兼容chrome,前面是兼容其它浏览器。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>要点二:oTop.style.left = screenw - oTop.offsetWidth +"px";  当页面加载时,让元素的位置位于页面最右边,用可视区的宽度减去元素本身的宽度。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>要点三:oTop.style.top = screenh - oTop.offsetHeight + scrolltop +"px"; 当页面滚动时,元素的Y坐标位置等于可视区的高度减去元素本身的高度,加上滚动距离。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>要点四:document.documentElement.scrollTop = document.body.scrollTop =0; 当点击元素时,让页面的滚动距离为0.写两个是为了兼容。</strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong><script></strong></span>
<span style="font-size: 18px;"><strong>window.onload = function(){</strong></span>
<span style="font-size: 18px;"><strong>  var oTop = document.getElementById("to_top");</strong></span>
<span style="font-size: 18px;"><strong>  var screenw = document.documentElement.clientWidth || document.body.clientWidth;</strong></span>
<span style="font-size: 18px;"><strong>  var screenh = document.documentElement.clientHeight || document.body.clientHeight;</strong></span>
<span style="font-size: 18px;"><strong>  oTop.style.left = screenw - oTop.offsetWidth +"px";</strong></span>
<span style="font-size: 18px;"><strong>  oTop.style.top = screenh - oTop.offsetHeight + "px";</strong></span>
<span style="font-size: 18px;"><strong>  window.onscroll = function(){</strong></span>
<span style="font-size: 18px;"><strong>    var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;</strong></span>
<span style="font-size: 18px;"><strong>    oTop.style.top = screenh - oTop.offsetHeight + scrolltop +"px";</strong></span>
<span style="font-size: 18px;"><strong>  }</strong></span>
<span style="font-size: 18px;"><strong>  oTop.onclick = function(){</strong></span>
<span style="font-size: 18px;"><strong>    document.documentElement.scrollTop = document.body.scrollTop =0;</strong></span>
<span style="font-size: 18px;"><strong>  }</strong></span>
<span style="font-size: 18px;"><strong>}  </strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong></script></strong></span>
<span style="font-size: 18px;"><strong>
</strong></span>
<span style="font-size: 18px;"><strong>============================================================================================</strong></span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值