一、居中
<script type="text/javascript">
$(function(){
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
$("#id").center();
})
</script>
<body>
<div id="id">居中显示</div>
</body>
二、禁用右键
$(document).bind("contextmenu",function(e){
return false;
});
三、ajax
//1
$.ajax({
url: 'stat.php',
type: 'POST',
data:{Name:"keyun"},
dataType: 'html',
timeout: 1000,
error: function(){alert('Error loading PHP document');},
success: function(result){
alert(result);
}
});
//2
$(":input[name=\'sub_btn\']").click(function(){
var $form = $("#store").serialize();
var uid=$("#cpId").val();
$.ajax({
type:"POST",
url:"updateAddress.ca",
dataType:"text",
data:$form,
asyns:false,
success:function(res){
if(res=="success"){
open_message("添加成功");
setTimeout(function(){
location.href="getStoreListByCpId.ca?id="+uid+"&pageNo=1&pageSize=15"
},2000)
}else{
open_message("添加失败");
}
}
})
})
//3
//激活
$.ajax({
type:"POST",
url:"activactionCp.ca?id="+id,
dataType:"text",
success:function(res){
if(res=="1"){
open_message("激活成功");
setTimeout(function(){
location.href="cpManagerPageInit.ca?pageNo="+pageNum;
},2000)
}else{
open_message("激活失败");
}
}
})
四、提示Message对照三
function open_message(message){
$("body").prepend("<div id='message_block'><div class='blank'></div><div id='message'><div class='message_text'>"+message+"</div></div></div>");
$("#message_block").css({"width":"130px","height":"100px","overflow":"hidden","position":"fixed","right":"5px","bottom": "40px", "z-index": "999"});
$(".blank").css({"width":"130px","height":"100px","margin":"0px","padding":"0px","visibility":"visible"});
$("#message").css({"width":"130px","height":"100px","background":"url(/images/message_2.png) no-repeat 0 0","margin":"0px",
//*url(images/message_2.png)
"padding":"0px"});
$(".message_text").css({"padding":"35px 10px 0px","line-height":"20px","text-align":"center","font-family":"微软雅黑",
"font-size":"12px","color": "#3C4145"});
var blank =$(".blank");
blank.slideUp(1500);
setTimeout( function() {
transition();
},2500);
function transition(){
blank.slideDown(1000);
}
}
五,恢复表单
$("#user")[0].reset();
六、禁用连接
<html>
<style>
.c{poorfish:expression(this.οnclick=function kill(){return false})}
</style>
<a class="c" href="#">哈哈</a>
<a href="#">呵呵</a>
</html>
七、判断是否为数字
if(/[^\d]/.test($yin)){
alert("印章请用数字表示");
return false;
}else{
return true;
}