admin管理员组文章数量:1317906
*@ JAVASCRIPT
$(document).ready(function()
{
}
)
function videochange(url) {
alert(url)
}
On the click of this button it wont hit the JavaScript function above. Any idea why? I really need to get that video.Value to a JavaScript function.....
@foreach(var video in Model.VideoList)
{
var url = video.Value;
<input type="button" value="@video.Text" onclick="javascript:videochange(url);" />
<br />
}
*@ JAVASCRIPT
$(document).ready(function()
{
}
)
function videochange(url) {
alert(url)
}
On the click of this button it wont hit the JavaScript function above. Any idea why? I really need to get that video.Value to a JavaScript function.....
@foreach(var video in Model.VideoList)
{
var url = video.Value;
<input type="button" value="@video.Text" onclick="javascript:videochange(url);" />
<br />
}
Share
Improve this question
edited Jan 6, 2014 at 12:16
BenMorel
36.6k51 gold badges205 silver badges336 bronze badges
asked Jun 19, 2013 at 13:07
Corey ToolisCorey Toolis
3071 gold badge3 silver badges21 bronze badges
0
3 Answers
Reset to default 2I would use JQuery. Assuming you've got version 1.7 or later, the following code should work. It also enforces a better separation between your markup and your JavaScript.
<div class="container">
@foreach(var video in Model.VideoList) {
<input type="button" value="@video.Text" data-url="@video.Value" />
}
</div>
<script>
$(document).ready(function(){
$('.container').on('click', 'input[type="button"]', function(){
var url = $(this).attr('data-url');
alert(url);
});
});
</script>
Try this
@foreach(var video in Model.VideoList)
{
var url = video.Value;
<input type="button" value="@v.Value" onclick="@String.Format("videochange('{0}')", url)" />
<br />
}
Try
@foreach(var video in Model.VideoList) {
<input type="button" value="@video.Text" onclick="videochange('@video.Value');" />
<br />
}
本文标签: aspnet mvcCall Javascript onClick not workingStack Overflow
版权声明:本文标题:asp.net mvc - Call Javascript onClick not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742031623a2416547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论