Get url variables from url to form with jquery

后端 未结 2 1465
死守一世寂寞
死守一世寂寞 2021-01-23 14:38

I have a html form which only shows a price, but don\'t submit anything to the server. This works fine now.

How can I add the function of running this form just from url

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-23 15:05

    if you want to take get vars from URL you can do it like this

    $(document).ready(function(){
        var getVars = getURLVariables();
        for(var i in getVars){
            if(i == "smoke"){
                $('#smoke').val(getVars[i]);
            }
        }
    
    });
    
    function getURLVariables(){
        var getVars = [];
        var split = location.href.split('?')[1].split('&');
        if(split != null){
            for(var i in split){
                var parts = split[i].split('=')
                getVars[parts[0]] = parts[1];
            }
        }   
    }
    

提交回复
热议问题