页面相关积累


----
checkbox控件实现单选功能:jq实现


{{{
<script type="text/javascript">
$(function(){
$("input:checkbox[name=cb]").change(function(){
var checked=$("input:checkbox[name=cb]:checked");
var obj=$(this);
if(obj[0].checked&&checked.length==2)(checked.get(0)==this?checked.get(1):checked.get(0)).checked=false;
});
});
</script>

}}}

----
checkbox list选中的个数:

{{{
$("input[name='cb']:checked").length
}}}


----
上传控件的实现:


{{{
HTML:
<tr>
<th width="15%">Kernel:</th>
<td><input type="file" id="eki_file" name="eki_file" value="{{eki_file}}"/> </td>
</tr>
<tr>
<th>Ramdisk:</th>
<td><input type="file" id="eri_file" name="eri_file" value="{{ eri_file }}"/></td>
</tr>
<tr>
<th>Rootfs:</th>
<td><input type="file" id="emi_file" name="emi_file" value="{{ emi_file }}"/></td>
</tr>
VIEW:
FILE_UPLOAD_DIR = /home/
def file_upload(file):
# upload file to dest
dest = open(FILE_UPLOAD_DIR + file.name,'wb+')
# split file in chunk
for chunk in file.chunks():
# write the chunk into dest
dest.write(chunk)
# close dest
dest.close()

if ('eki_file' in request.FILES) and ('eri_file' in request.FILES) and ('emi_file' in request.FILES):
eki_obj = request.FILES['eki_file']
eri_obj = request.FILES['eri_file']
emi_obj = request.FILES['emi_file']
if eki_obj and eri_obj and emi_obj:
file_upload(eki_obj)
file_upload(eri_obj)
file_upload(emi_obj)
eki_file_location = FILE_UPLOAD_DIR + eki_obj.name//上传到目标机的位置
eri_file_location = FILE_UPLOAD_DIR + eri_obj.name
emi_file_location = FILE_UPLOAD_DIR + emi_obj.name

}}}


----
登录时保存用户名,密码:js


{{{
//新建cookie。
//hours为空字符串时,cookie的生存期至浏览器会话结束。hours为数字0时,建立的是一个失效的cookie,这个cookie会覆盖已经建立过的同名、
同path的cookie(如果这个cookie存在)。
function setCookie(name,value,hours,path){
var name = escape(name);
var value = escape(value);
var expires = new Date();
expires.setTime(expires.getTime() + hours*3600000);
path = path == "" ? "" : ";path=" + path;
_expires = (typeof hours) == "string" ? "" : ";expires=" + expires.toUTCString();
document.cookie = name + "=" + value + _expires + path;
}
//获取cookie值
function getCookieValue(name){
var name = escape(name);
//读cookie属性,这将返回文档的所有cookie
var allcookies = document.cookie;
//查找名为name的cookie的开始位置
name += "=";
var pos = allcookies.indexOf(name);
//如果找到了具有该名字的cookie,那么提取并使用它的值
if (pos != -1){ //如果pos值为-1则说明搜索"version="失败
var start = pos + name.length; //cookie值开始的位置
var end = allcookies.indexOf(";",start); //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置
if (end == -1) end = allcookies.length; //如果end值为-1说明cookie列表里只有一个cookie
var value = allcookies.substring(start,end); //提取cookie的值
return unescape(value); //对它解码
}
else return ""; //搜索失败,返回空字符串
}
//删除cookie
function deleteCookie(name,path){
var name = escape(name);
var expires = new Date(0);
path = path == "" ? "" : ";path=" + path;
document.cookie = name + "="+ ";expires=" + expires.toUTCString() + path;
}

function login()
{

cb = document.getElementById("saveCookie")
name = document.getElementById("username")
psw = document.getElementById("userpassword")
if( cb.checked ){

setCookie("username",name.value,24,"/");
setCookie("password",psw.value,24,"/");
}
else
{

deleteCookie("username","/");
deleteCookie("password","/");
}
}
window.onload = function(){

var userNameValue = getCookieValue("username");
document.getElementById("username").value = userNameValue;
var passwordValue = getCookieValue("password");
document.getElementById("userpassword").value = passwordValue;

}

}}}

----

== js Date ==

var t = new Date(2010,1,31);
发现结果竟然是2010-3-1,查阅资料发现,Date()中的月份是从0-11,因此在早不到相应日期之后,自动向后推算,因此,应该month-1


== button 按钮 不提交表单 ==

{{{
<button type="button" onclick="window.location.href=''">000</button>
}}}

== 标签 居中 ==
margin:0 auto;align:center

原文地址:https://www.cnblogs.com/codinggirl/p/2995375.html