ASP MVC 2 Dynamic Href By Javascript

佐手、 提交于 2019-12-11 16:17:37

问题


Here is the deal:

My link:

<li><% =Html.ActionLink("Scheme", null, null, null, new { @id = "schemeid" })%></li>

JavaScript for changing href:

<script>
    document.getElementById('schemeid').href= "Test/ALL";
</script>

Its working in any browser on ASP.NET dev.server on vs2010; but when i host it on iis 7. it fails. and in source of web page i have href=""

can any one help?


回答1:


First of all, try using Firefox and check "Console Errors" to see if you got any javascript error. Second, try this:

<script>
    $(document).ready(function () {
        document.getElementById('schemeid').href= "Test/ALL";
    });
</script>

You'll need jQuery. Maybe your script is executing before rendering the tag.




回答2:


found solution. thx to every body. here is answer:

document.getElementById('list').innerHTML='<% =Html.ActionLink("Scheme","ALL","Test")%>';

<li id="list"><% =Html.ActionLink("Scheme", null, null)%></li>    


来源:https://stackoverflow.com/questions/3541918/asp-mvc-2-dynamic-href-by-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!