开发者

Pass input variable into jquery load function

开发者 https://www.devze.com 2023-02-07 08:04 出处:网络
I have an input field and I want that variable to be passed as part of the url paramter in a load request.So for example what I am trying is

I have an input field and I want that variable to be passed as part of the url paramter in a load request. So for example what I am trying is

var inputField= $j('#inputText').val开发者_开发百科();
$j(document).ready(function() {     
    $j(".button").click(function (){    
        $j('#result').load('http://site.com?parameter='+inputField'.aClass')
    });
});

If I were trying to do this without the variable like

$j('#result').load('http://site.com?parameter=stuff .aClass')

it works fine

Can someone please show me the correct syntax to make this work?


You are missing a + in your code.

Try this(changed the code to include the $j('#inputText') in the ready event..just in case..

$j(document).ready(function() {     
   var inputField= $j('#inputText').val();
    $j(".button").click(function (){    
        $j('#result').load('http://site.com?parameter='+inputField +' .aClass')
    });
});


$j(document).ready(function() {     
    $j(".button").click(function (){
        var inputField= $j('#inputText').val();    
        $j('#result').load('http://site.com?parameter='+inputField+' .aClass')
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消