开发者

Passing variable to jQuery .load function

开发者 https://www.devze.com 2023-04-03 09:11 出处:网络
can I pass variable (variable named test in this case) to jQuery .load function? $(document).ready(function() {

can I pass variable (variable named test in this case) to jQuery .load function?

$(document).ready(function() {  
$('a').clic开发者_如何学JAVAk(function(e) {
    e.preventDefault();
    var test= $(this).attr('href');
        $('.window').load($(test));     

});

This doesn't work.


You are wrapping your url in a call to jQuery. Just pass test, not $(test).

$(document).ready(function() {  
    $('a').click(function(e) {
        e.preventDefault();
        var test= $(this).attr('href');
        $('.window').load(test);        
    });
});

Also, you are missing the closing }); in your sample code. Not sure if it's a typo here or in your actual code.


In your code, test is a string. .load should take that string, not a jQuery object.

$('.window').load(test);

ought to work.

0

精彩评论

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