Get parameter values from href in jquery

前端 未结 2 1895
温柔的废话
温柔的废话 2020-12-06 11:39

Script

 

        
2条回答
  •  忘掉有多难
    2020-12-06 12:25

    You can do as soeme thing as below

    $('a').bind('click',function(){
        var url = ($(this).attr('href'));
        var cat = getURLParameter(url, 'cat');
        var typ = getURLParameter(url, 'typ');
        //calling the ajax function
        pop(cat, typ)
    });
    
    
    function getURLParameter(url, name) {
        return (RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1];
    }
    
    function pop(cat, typ) {
    
        $.ajax({
           type:'post',
           url:site_url()+'/event/deleteEventSingle',
           data:{'cat':cat,'type':typ},
            async:false,
             success:function(result){}
        });
    }
    

    Check out the the example at Live fiddle http://jsfiddle.net/mayooresan/aY9vy/

提交回复
热议问题