简体   繁体   中英

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

     <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

You can send values via query string in anchor tag URL. but these can be seen by others.

Or You can send via JavaScript onclick event

Pass the url and params to javascript method and send those via this method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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