常用js/jsonp跨域

判断是否存在某个字符

var url=window.location.href;
	var patt = new RegExp('itemid');
	if(patt.test(url)){//字符串存在返回true否则返回false
		alert(1);
	}else{
		alert(0);
	}

获取属性值:

var username=$(this).attr("abbr");


1. Javascript 返回上一页history.go(-1), 返回两个页面: history.go(-2);

history.back();

页面刷新:

window.location.reload();

页面跳转:

window.location.href="http://zizhi.whxhkj.net/notice/list.php";

AJAX:

function() {
    $('.btn').click(function() {
        var itemid = $('#itemid').val();
        var type = $('input:radio:checked').val();
        var company = $('#company').val();
        var address = $('#address').val();
        var truename = $('#truename').val();
        var telephone = $('#telephone').val();
        var service = $('#service').val();
        //alert(telephone);
        if (itemid == 0) {
            var data = "itemid=0&type=" + type + "&company=" + company + "&address=" + address + "&truename=" + truename + "&telephone=" + telephone + "&service=" + service;
        } else {
            var data = "itemid=" + itemid + "&type=" + type + "&company=" + company + "&address=" + address + "&truename=" + truename + "&telephone=" + telephone + "&service=" + service;
        }
        //alert(data);
        $.ajax({
            type: 'post',
            url: './ajax.php',
            data: data,
            async: false,
            success: function(msg) {
                if (msg == 1) {
                    //alert('修改成功');
                    //location.reload();
                }
            },
            error: function(msg) {
},
        });

全选反选:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> 
</head>
<body>
您的爱好很广泛!!!
        <br>
        <input type="checkbox" name="checkItems" id="checkItems" value="全选/全不选"/>全选/全不选
        <br>
        <input type="checkbox" name="items" value="足球" />足球
        <input type="checkbox" name="items" value="篮球"/>篮球
        <input type="checkbox" name="items" value="游泳"/>游泳
        <input type="checkbox" name="items" value="唱歌"/>唱歌
        <br>
        <input type="button" name="checkall" id="checkall" value="全选" />
        <input type="button" name="checkall" id="checkallNo" value="全不选" />
        <input type="button" name="checkall" id="check_revsern" value="反选" />
</body>
</html>

JS:

<script>
$(document).ready(function(){
    $("#checkall").click(function(){
        $("input[name='items']").each(function(){
            this.checked = true;
        });
    });
     
    $("#checkallNo").click(function(){
        $("input[name='items']").each(function(){
            this.checked = false;
        })
    });
     
    $("#check_revsern").click(function(){
        $("input[name='items']").each(function(){
            if (this.checked) {
                this.checked = false;
            }
            else {
                this.checked = true;
            }
        });
    });
     
    $("#checkItems").click(function(){
        $("input[name='items']").each(function(){
            if (this.checked) {
                this.checked = false;
            }
            else {
                this.checked = true;
            }
        });
    });
});
</script>

$.ajax jsonp

<script>
$(document).ready(function(){
	var api='http://api.k780.com:88/?app=life.time&appkey=12311&sign=7c4ae114b95a207997e9765f1ccca59e&format=json&jsoncallback=bjtime';
	
	$.ajax({url:api,type:'get',dataType:'jsonp','jsonpCallback':'bjtime',success:function(data){alert(data.result.datetime_1);}});
});
</script>


你可能感兴趣的:(常用js/jsonp跨域)