Sri*_*vas 1 javascript asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4
我在视图中有此操作链接:
@Html.ActionLink("Edit", "Edit", null, new {@id="editLink", @class="button"})
Run Code Online (Sandbox Code Playgroud)
我想调用一个java脚本方法在运行时从我的Selected List Box Item中生成URI.
@Html.ListBox("EmployeeName", (IEnumerable<SelectListItem>)ViewBag.selectlist, new { @id = "saglistbox", @class = "SAGListbox" })
Run Code Online (Sandbox Code Playgroud)
作为第一步,当我尝试使用JavaScript显示警报时:
<script type="text/javascript">
$('#editLink').click(function () {
alert("hello");
});
</script>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,这没有按预期工作.
在DOM完全加载时,您没有绑定事件.
<script>
$(function () {
$('#editLink').click(function () {
alert("hello");
//To get selected value use
var selected = $("#EmployeeName").find(':selected').text();
//To stop default behaviour
return false;
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
其次,make the URI at runtime from my Selected List Box Item你必须停止它所使用的默认行为return false
| 归档时间: |
|
| 查看次数: |
7506 次 |
| 最近记录: |