c# - Generate jQuery functions dynamically mvc 4 razor -


currently, passing list of object controller view, , generate labels object's name.

what trying generate jquery function dynamically create functions (toggle form relative lable id) each label after being clicked.

the jquery function not working, not output corrent jquery function in webpage...... give me soem hints?

<table>     @foreach (var item in model)     {         <tr>             <td>                 @html.label(item.productname, new { @id = item.productid})             </td>         </tr>         } </table>   <script type="text/javascript">     $(document).ready(function () {         @foreach (var item in model)     {         $(@item.productid).click)(function({             //do        }));     }      }); </script> 

thanks much!

your js syntax wrong, starters. want give labels class name (such product_lbl) or data attribute (if don't semantic class names) such product-lbl. way don't have second loop add click event handlers. you'll need one, so:

$('.product_lbl').on(     'click',      function() { /* whichever label clicked */ } ); 

or

$('[product-lbl]').on(     'click',      function() { /* whichever label clicked */ } ); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -