您的位置:首页 > 其它

每天学一点7

2015-07-13 01:56 381 查看
1.注意:任何地方省略var关键字,定义的变量都是“全局变量”,因此,一般情况下,不要省略var关键字。

2.JavaScript 注释单行的注释以 //开始;多行注释以 /* 开头,以 */ 结尾

3.php中 isset()函数的作用是判断一个变量是否定义过。

4.内置函数str_replace可以实现字符串的替换。.

例子 $arr = “苹果很好吃”;

$arr = str_replace(‘苹果’,‘香蕉’,$arr);

echo$arr; 结果是 香蕉很好吃

5.当我们创建了自定义函数,并且了解了可变函数的用法,为了确保程序调用的函数是存在的,经常会先使用function_exists判断一下函数是否存在。同样的method_exists可以用来检测类的方法是否存在。

function func() {

}

if (function_exists('func')){

echo 'exists';

}


类是否定义可以使用class_exists。

class MyClass{

}

// 使用前检查类是否存在

if (class_exists('MyClass')) {

$myclass = new MyClass();

}


6.js和php中try catch用法实例

<html>

<script>

function checkNum(number){

if(number){

throw new Exception(" 抛出错误");

}

returntrue;

}

try{

checkNum(2);

}catch( e){

alert("抛出错误");

}

</script>

<?php

header("Content-type: text/html;charset=utf-8");

function checkNum($number)

{

if($number>1){

throw new Exception("Value must be 1 or below");

}

return true;

}

try{

checkNum(2);

}catch(Exception $e){

echo$e->getMessage();

}

?>

</html>

7.如果有一个文件夹,专门用于定义类,则命名规范应当这样:类名.class.php

8.<ahref ="javascript:vido(0);"></a>;链接为空。

9.一般修改或许量的样式为 xx.style.display="none";

或者在style里面写个class样式如 .xx{display:none;}

xx.className= “xx”;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: