开发者

How to send the values in paths in jquery?

开发者 https://www.devze.com 2022-12-23 01:22 出处:网络
I\'m using the foll开发者_JAVA技巧owing code.. $(document).ready(function(){ $(\"#test a\").click(function(){

I'm using the foll开发者_JAVA技巧owing code..

$(document).ready(function(){   
    $("#test a").click(function(){
      var labelTo = $(this).text();
      window.location = '#{root_path(labelTo)}';

    });
 });

I just want to send the value labelTo in root_path..but its giving following error

undefined local variable or method `labelTo' for #

any solution??


If root_path is a function which returns something then you can use like this

$(document).ready(function(){   
    $("#test a").click(function(){
      var labelTo = $(this).text();
      window.location = '#' + root_path(labelTo);
    });
});


The obvious thought that comes to mind is

window.location = '#{root_path(' + labelTo + ')}';

but what are those braces for?

0

精彩评论

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