m_Orchestrate learning system---三十三、公共变量多弄成全局变量
m_Orchestrate learning system---三十三、公共变量多弄成全局变量
一、总结
一句话总结:比如班级id,小组id,这样省事,而且减少数据库的访问,加快访问速度,而且节约代码
全局变量 访问速度
1、jquery查看checkbox是否被选中?
prop
直接jquery手册查看prop
参数name 描述:
选中复选框为true,没选中为false
jQuery 代码:
$("input[type='checkbox']").prop("checked");
参数properties 描述:
禁用页面上的所有复选框。
jQuery 代码:
$("input[type='checkbox']").prop({
disabled: true
});
参数key,value 描述:
禁用和选中所有页面上的复选框。
jQuery 代码:
$("input[type='checkbox']").prop("disabled", true);
$("input[type='checkbox']").prop("checked", true);
参数key,回调函数 描述:
通过函数来设置所有页面上的复选框被选中。
jQuery 代码:
$("input[type='checkbox']").prop("checked", function( i, val ) {
return !val;
});
<script>
//checkbox选中逻辑
//父亲checkbox没被选上,那么点父亲check_box的时候就是全选
//父亲checkbox被选上,那么点父亲check_box的时候就是全不选 //所有的子checkbox都被选中
function select_all_fry_checkbox_child() {
$('.fry_checkbox_child').each(function () {
$(this).prop("checked", true);
});
}
//所有的子checkbox都不被选中
function not_select_all_fry_checkbox_child() {
$('.fry_checkbox_child').each(function () {
$(this).prop("checked", false);
});
} //判断所有的子checkbox是否都被选中
function is_fry_checkbox_child_all_checked(){
$('.fry_checkbox_child').each(function () {
if(!$(this).prop("checked")){
//console.log('no');
return false;
}
});
//console.log('yes');
return true;
} //判断父亲checkbox是否被选中
function is_fry_checkbox_parent_checked(){
if($('.fry_checkbox_parent').prop("checked")){
//console.log('no');
return true;
}
return false;
} //checkbox的选中逻辑
function fry_checkbox(){
//父亲checkbox没被选上,那么点父亲check_box的时候就是全选
//父亲checkbox被选上,那么点父亲check_box的时候就是全不选
$('.fry_checkbox_parent').click(function () {
if(is_fry_checkbox_parent_checked()){
select_all_fry_checkbox_child();
}else{
not_select_all_fry_checkbox_child();
}
}); } $(function () {
fry_checkbox();
}); </script>
2、一行字体截断效果?
宽 高
一定注意,不仅要限制宽度,还要限制高度
这里是已经限制了宽度,所以代码里面没有限制宽度的代码
1 <p style="word-wrap: normal;text-overflow: ellipsis;white-space: nowrap;overflow: hidden;height: 20px;line-height: 20px;">{$message_vo.sf_content}</p>

3、报“未定义数组索引: u_picture”错误?
重名
出错原因:基础控制器base中定义了$user,管理员界面也定义了$user,而且两个的内容不一样,
所以在导航和顶部用了user,页面的user就出错了
4、如果要使用in_array函数的话,数组最好被初始化为[]而不是null?
数组 初始化 []
因为in_array的第二个参数是数组
所以,所有的数组我要初始化为[],而现在我已经习惯初始化为null了,
这样可以避免超级多的错误
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
5、select中-1做all的值的时候,后台的判断语句应该是>0,而不是!=-1?
null >0
因为初始没传值进去的时候值为null
public function index()
{
$d_id=input('d_id');
$this->assign('d_id',$d_id); //將學科信息傳遞到頁面
$disciplines=db('discipline')->select();
$this->assign('disciplines',$disciplines); $map=null;
//dump($d_id);die;
if($d_id>0) $map['p_d_id']=$d_id;
$projects=db('project')->where($map)->select();
$this->assign('projects',$projects);
return view();
}
<select class="form-control btn-sm" name="d_id" id="d_id" onchange="javascript:location.href=this.value;">
<option value="{:url('discipline.project/index',array('d_id'=>-1))}" selected >All</option>
{volist name="disciplines" id="vo"}
<option value="{:url('discipline.project/index',array('d_id'=>$vo.d_id))}" {if condition="$vo.d_id eq $d_id"}selected{/if} >{$vo.d_name}</option>
{/volist}
</select>
6、php函数strtotime使用时候的一点注意点(/-.分别代表的日期格式)?
/ American M/D/Y
- European D-M-Y
. ISO Y.M.D
就是用/的时候不支持dd/mm/yyyy的模式,用-或者.的话都支持
I've had a little trouble with this function in the past because (as some people have pointed out) you can't really set a locale for strtotime. If you're American, you see 11/12/10 and think "12 November, 2010". If you're Australian (or European), you think it's 11 December, 2010. If you're a sysadmin who reads in ISO, it looks like 10th December 2011.
The best way to compensate for this is by modifying your joining characters. Forward slash (/) signifies American M/D/Y formatting, a dash (-) signifies European D-M-Y and a period (.) signifies ISO Y.M.D.
Observe:
<?php
echo date("jS F, Y", strtotime("11.12.10"));
// outputs 10th December, 2011 echo date("jS F, Y", strtotime("11/12/10"));
// outputs 12th November, 2010 echo date("jS F, Y", strtotime("11-12-10"));
// outputs 11th December, 2010
?>
Hope this helps someone!
7、php保留两位小数?
round() sprintf() number_format()
$num = 10.4567;
//第一种:利用round()对浮点数进行四舍五入
echo round($num,2); //10.46
//第二种:利用sprintf格式化字符串
$format_num = sprintf("%.2f",$num);
echo $format_num; //10.46
//第三种:利用千位分组来格式化数字的函数number_format()
echo number_format($num, 2); //10.46
//或者如下
echo number_format($num, 2, '.', ''); //10/46
8、js随机从一个数组中取出几个元素?
Math.random()
JS如何从一个数组中随机取出一个元素或者几个元素。
假如数组为
var items = ['1','2','4','5','6','7','8','9','10'];
1.从数组items中随机取出一个元素
//code from http://caibaojian.com/js-get-random-elements-from-array.html
var item = items[Math.floor(Math.random()*items.length)];
2.从前面的一篇随机数组中随机取几个元素
function getRandomArrayElements(arr, count) {
var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}
var items = ['1','2','4','5','6','7','8','9','10'];
console.log( getRandomArrayElements(items, 4) );
9、js判断变量未定义?
typeof a == "undefined"
控制台输出未定义变量a会报错:

我们打印出a的数据类型是:

我们可以看到未定义变量的数据类型是 “undefined”
所以判断js变量是否未定义的方法就是
typeof a != "undefined" ? true : false;
//如果沒定義筆刷,就在數組裡面隨機選就好了,多簡單
if(typeof olddata.brush == "undefined") olddata.brush=fry_brush_group[Math.floor(Math.random()*fry_brush_group.length)];
10、原生js增加和移除disabled属性?
setAttribute disabled 属性
增加
document.getElementById("fry_add_first_btn").setAttribute('disabled','disabled'); 移除
document.getElementById("fry_add_first_btn").disabled="";
二、内容在总结中
m_Orchestrate learning system---三十三、公共变量多弄成全局变量的更多相关文章
- m_Orchestrate learning system---十三、thinkphp的验证器支持多语言么
m_Orchestrate learning system---十三.thinkphp的验证器支持多语言么 一.总结 一句话总结:支持,不仅验证器支持,其它的插件应该都支持 不仅thinkphp支持多 ...
- Python - 面向对象(三)公共变量,受保护变量,私有变量
前言 在Python的类里面,所有属性和方法默认都是公共的:但Python也可以设置受保护.私有类型的变量or方法 受保护类型的变量.方法 一般称为:protected变量 #!/usr/bin/en ...
- m_Orchestrate learning system---二十三、如何搜索概念图插件
m_Orchestrate learning system---二十三.如何搜索概念图插件 一.总结 一句话总结:要在百度你们搜索前端组件,前端组件 概念图工具,js概念图工具等等这些 用的话用go ...
- m_Orchestrate learning system---十九、局部变量和块变量是什么
m_Orchestrate learning system---十九.局部变量和块变量是什么 一.总结 一句话总结:下面的global的使用情况可以很好的解释这个问题 这是在一个函数里面,只不过里面有 ...
- Machine Learning - 第6周(Advice for Applying Machine Learning、Machine Learning System Design)
In Week 6, you will be learning about systematically improving your learning algorithm. The videos f ...
- m_Orchestrate learning system---三十四、使用重定义了$的插件的时候最容易出现的问题是什么
m_Orchestrate learning system---三十四.使用重定义了$的插件的时候最容易出现的问题是什么 一.总结 一句话总结:如下面这段代码,定义了$的值,还是会习惯性的把$当成jQ ...
- m_Orchestrate learning system---二十九、什么情况下用数据库做配置字段,什么情况下用配置文件做配置
m_Orchestrate learning system---二十九.什么情况下用数据库做配置字段,什么情况下用配置文件做配置 一.总结 一句话总结: 配置文件 开发人员 重置 数据库 非开发人员 ...
- m_Orchestrate learning system---二十五、复制类的时候最容易出现的错误是什么
m_Orchestrate learning system---二十五.复制类的时候最容易出现的错误是什么 一.总结 一句话总结:命名空间错误导致Analyze类虽然继承了Base类,但是没有执行里面 ...
- NeHe OpenGL教程 第三十三课:TGA文件
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
随机推荐
- codeforces 461C
这题说的是 给了一张长方形的纸 1*n 然后可以按照不同的做法去折这个纸张 他有两种操作,操作1 给了一个pi 点 然后将左边的纸往右边折,第2种操作是给了一个L 和 R 然后计算出 L和R 之间的纸 ...
- ios 透过上层视图点击相应下方视图的点击事件
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ UIView *hitView = [super hitTest:point ...
- Linux命令: 结束命令
1)ctrl+c,退出命令 2)q,退出文件
- Jquery图片上传组件,支持多文件上传
Jquery图片上传组件,支持多文件上传http://www.jq22.com/jquery-info230jQuery File Upload 是一个Jquery图片上传组件,支持多文件上传.取消. ...
- Windows下MongoDB安装
1.解压mongodb-win32-i386-1.8.1.zip ,创建路径d:\mongodb ,将解压后的Bin文件Copy to 此文件夹下 2.d:\mongodb 下建立Data文件夹 d: ...
- 在python3下使用OpenCV 显示图像
在Python3下用使用OpenCV比在C,C++里开发不止快捷一点点, 原型开发的时候蛮有用. 这里用的OpenCV 加载图片, 用的imshow画图 # -*- coding: utf-8 -*- ...
- bzoj1648 / P2853 [USACO06DEC]牛的野餐Cow Picnic
P2853 [USACO06DEC]牛的野餐Cow Picnic 你愿意的话,可以写dj. 然鹅,对一个缺时间的退役选手来说,暴力模拟是一个不错的选择. 让每个奶牛都把图走一遍,显然那些被每个奶牛都走 ...
- 基础知识 - Golang 中的格式化输入输出
------------------------------------------------------------ [格式化输出] // 格式化输出:将 arg 列表中的 arg 转换为字符串输 ...
- this逃逸
首先,什么是this逃逸? this逃逸是指类构造函数在返回实例之前,线程便持有该对象的引用. 常发生于在构造函数中启动线程或注册监听器. eg: public class ThisEscape { ...
- [LeetCode] 701. Insert into a Binary Search Tree
Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert t ...