Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a razor syntax like this:

   foreach(var item in model)
 {
<td><a href ="#"  onclick="Getinfo(@item.email);" >6/16/2016 2:02:29 AM</a>  </td>
 }

My javascript that recieves the request goes like this:

<script type="text/javascript" src="~/Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript">
    function Getinfo(elem) {
        var email = document.getElementById(elem).innerHTML;
    }
</script>

When clicking on the href link, I get the following error in the console of the browser:

"Uncaught SyntaxError: Invalid or unexpected token",

and this part is underlined:

    **</a>  </td>**

I am a beginner so I get stuck in syntax a lot. If it is that then please help me out.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
654 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should pass @item.email in quotes then it will be treated as string argument

<td><a href ="#"  onclick="Getinfo('@item.email');" >6/16/2016 2:02:29 AM</a>  </td>

Otherwise, it is treated as variable thus error is generated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...