简体   繁体   English

通过单击锚标记来获取锚的价值

[英]getting value of anchor by clicking on anchor tag

getting value of anchor tag by clicking on anchor tag in javascript and i want to pass the value to controller 通过单击javascript中的锚标记来获取锚标记的值,我想将该值传递给控制器

     <div class=form-actions>
           <% @sitename.each do | rec | %>
              <a id="<%=rec.site%>" data-rel="tooltip" value=<%=rec.site%>"title="Total access in bangalore."      
                 class="well span2 top-block sri" href="#">
                    <span class="icon32 icon-green icon-Users"></span>
                      <div><%=rec.site%></div>
                        <div id="loading-indicator" style="display: none;">
                          <%= image_tag("peregrine-loader.gif") %>
                    </div>
                   <div class="counter"><%=rec.cnt%></div>
                        <span class="notification">today</span>
            </a>
         <% end%>
         <!-- Summary counters - END -->
    </div>

    <script type=text\JavaScript>
        $('.sri').live('click' , function(){
             var x= $(this).val();
              alert x;

        </script>

java script code not working ,my question is how to get value of anchor when click on corresponding button (here button means form view code output :we get different square box if click on that box i need that corresponding value in one variable and i want pass that to controller) for example first button name=blore and second button=pune if i click on blore button i want that button value and if i click on pune button i want pune button value in one varible Java脚本代码不起作用,我的问题是如何在单击相应的按钮时获取锚的值(此处按钮表示表单视图代码输出:如果单击该框, 我们将得到不同的方框 ,我需要在一个变量中使用相应的值,我想要将其传递给控制器​​)​​,例如第一个按钮名称= blore,第二个按钮= pune,如果我单击blore按钮,我想要该按钮的值,如果我单击pune按钮,我想要在一个变量中的pune按钮的值

You can send values via query string in anchor tag URL. 您可以通过锚标记URL中的查询字符串发送值。 but these can be seen by others. 但是这些可以被其他人看到。

Or You can send via JavaScript onclick event 或者您可以通过JavaScript onclick事件发送

Pass the url and params to javascript method and send those via this method. 将url和params传递给javascript方法,然后通过此方法发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM