为什么我js代码没执行
<scripttype="text/javascript">functionshow(){varul=document.getElementById("searchinf...
<script type="text/javascript">
function show() {
var ul = document.getElementById("searchinfo");
if (ul.style.display == none) {
ul.style.display = "";
}
else {
ul.style.display = none;
}
}
</script>
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
<ul class="nav navbar-nav navbar-right">
<li><a href="#" onclick="show()">Search</a>
<ul id="searchinfo" style="display:none">
<li>@Html.ActionLink("SearchAttendance", "SearchAttendance", "Search", routeValues: null, htmlAttributes: new { id = "SearchAttendanceLink" })</li>
<li>@Html.ActionLink("SearchSN", "SearchSN", "Search", routeValues: null, htmlAttributes: new { id = "SearchSNLink" })</li>
<li>@Html.ActionLink("SearchEmployee", "SearchEmployee", "Search", routeValues: null, htmlAttributes: new { id = "SearchEmployeeLink" })</li>
</ul>
</li>
<li>@Html.ActionLink("AddUser", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>
@Html.ActionLink("Hello," + User.Identity.Name + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Logout</a></li>
</ul>
}
}
我把js那部分删掉,然后将<a href="#" onclick="show()">Search</a>改成<a href="#" onclick="$('#searchinfo').toggle();">Search</a>,然后效果可以出来了,但是我想问的是,为什么像我之前那样,将js代码放在外面就执行不了呢? 展开
function show() {
var ul = document.getElementById("searchinfo");
if (ul.style.display == none) {
ul.style.display = "";
}
else {
ul.style.display = none;
}
}
</script>
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
{
<ul class="nav navbar-nav navbar-right">
<li><a href="#" onclick="show()">Search</a>
<ul id="searchinfo" style="display:none">
<li>@Html.ActionLink("SearchAttendance", "SearchAttendance", "Search", routeValues: null, htmlAttributes: new { id = "SearchAttendanceLink" })</li>
<li>@Html.ActionLink("SearchSN", "SearchSN", "Search", routeValues: null, htmlAttributes: new { id = "SearchSNLink" })</li>
<li>@Html.ActionLink("SearchEmployee", "SearchEmployee", "Search", routeValues: null, htmlAttributes: new { id = "SearchEmployeeLink" })</li>
</ul>
</li>
<li>@Html.ActionLink("AddUser", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
<li>
@Html.ActionLink("Hello," + User.Identity.Name + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Logout</a></li>
</ul>
}
}
我把js那部分删掉,然后将<a href="#" onclick="show()">Search</a>改成<a href="#" onclick="$('#searchinfo').toggle();">Search</a>,然后效果可以出来了,但是我想问的是,为什么像我之前那样,将js代码放在外面就执行不了呢? 展开
3个回答
展开全部
ul.style.display == none改成ul.style.display == 'none',
不加引号会认为是变量
不加引号会认为是变量
更多追问追答
追问
主要是根本没执行js里面的代码。。
追答
审查元素看有没有报错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不要等于none 换成 null 或 “” 都行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<a href="javascript:0">试试</a>
更多追问追答
追问
没用,之前试过了0.0
追答
a href="javascript:void(0);" onclick="show()"
或者 href="javascript:show();"
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询