gpt4 book ai didi

MVC 升级后 Javascript 功能不起作用

转载 作者:行者123 更新时间:2023-11-27 23:30:58 24 4
gpt4 key购买 nike

我已将解决方案从 MVC 3 升级到 MVC 4。

我有 2 个特定的 JavaScript 函数在升级后不再工作。

  1. 标签

这就是选项卡现在的呈现方式

Tab Rendering

我怀疑这与新框架的 JavaScript 版本有关?我不确定。

代码:

<script type="text/javascript">
$(function () {
$("#tabs").tabs();

$('.taberize').each(function () {
var e = $(this);
var panels = e.parents('.ui-tabs-panel');
if (panels.length == 0) { return; }
var tabId = $(panels[0]).attr('id');
e.attr('href', e.attr('href') + '#' + tabId);
});

$(".container").each(function (e) {
var height = $(document).height() - 230;
$(this).height(height);
});
});

<小时/> 2.行上悬停功能

On-Row-Hover 功能不再起作用,我的 WebGrid 左侧有一个“操作菜单”,在行悬停时,它显示“编辑”和“详细信息”菜单等功能...这是在JavaScript。

<script type="text/javascript">
var prevRow = null;
$('#gridData table tbody tr').not(':first').hover(function()
{
$('#myMenu').hide();
if (prevRow != this)
{

if (prevRow != null)
{
$(prevRow).css("background","");
$('.actionButtons', $(prevRow)).hide();
}

$(this).css("background","#EDEFFF");
$('.actionButtons', $(this)).show();
prevRow = this;
}
},
function()
{
if (!$('#myMenu').is(":visible"))
{
if (prevRow != null)
{
$(prevRow).css("background","");
$('.actionButtons', $(prevRow)).hide();
prevRow = null;
}
}
});

$(".openmenu").contextMenu({ menu: 'myMenu', leftButton: true },
function(action, el, pos) {
contextMenuWork(action, el.parents('tr')[0].id , pos);

});

function contextMenuWork(action, id) {
switch (action) {

case "insert":
{
if($.browser.msie&&$.browser.version.substr(0,1)<8){var url='@Url.Action("Create", "Account")';document.location=url}else{CreateNewAccount()}
break;
}
case "createtask":
{
var url = '@Url.Action("CreateFromAccount", "UserTask")' + '/' + id;
document.location = url;
break;
}
case "linkassessment":
{
var url = '@Url.Action("CreateFromAccount", "Questionnaire")' + '/' + id;
document.location = url;
break;
}
case "details":
{
var url = '@Url.Action("Details", "Account")' + '/' + id;
document.location = url;
break;
}
case "edit":
{
var url = '@Url.Action("Edit", "Account")' + '/' + id;
document.location = url;
break;
}
case "createperson":
{
if($.browser.msie&&$.browser.version.substr(0,1)<8){var url='@Url.Action("Create", "Person")';document.location=url}else{CreateNewPerson(id)}
break;
}
case "createopportunity":
{
var url = '@Url.Action("Create", "Opportunity")' + '/' + id;
document.location = url;
break;
}

}

}

});
</script>

<div id="gridData">
<ul id="myMenu" class="contextMenu" style="display: none">
<li class="insert"><a href="#insert" id="create">Create New</a></li>
<li class="detail"><a href="#details">Details</a></li>
<li class="edit"><a href="#edit">Edit</a></li>
</ul>
</div>
<table>
<tr>
<th class="field-actions-account" style="width: 75px">
<a href="#">Actions</a>
</th>
<tr id="@Html.Encode(item.AccountID)">
<td>
<div class="actionButtons" style="display:none">
<a href="@Url.Action("Edit", new { id = item.AccountID }) " style="text-decoration:none" title="Edit"><img src="@Html.Raw(@Url.Content("~/Content/img/document-pencil-icon.png"))" alt="Edit" title="Edit" style="border:none"/> </a>
<a href="@Url.Action("Details", new { id = item.AccountID }) " style="text-decoration:none" title="Details"><img src="@Html.Raw(@Url.Content("~/Content/img/testDetailsIcon.gif"))" alt="Details" title="Details" style="border:none" /> </a>
<img src="@Html.Raw(@Url.Content("~/Content/img/options.gif"))" alt="More Options" class="openmenu" title="More Options"/>
</div>

最佳答案

将您的 javascript 代码放入如下部分:

  @section Head
{
<script type="text/javascript">
$(function () {
$("#tabs").tabs();

$('.taberize').each(function () {
var e = $(this);
var panels = e.parents('.ui-tabs-panel');
if (panels.length == 0) { return; }
var tabId = $(panels[0]).attr('id');
e.attr('href', e.attr('href') + '#' + tabId);
});

$(".container").each(function (e) {
var height = $(document).height() - 230;
$(this).height(height);
});
});
</script>
}

然后确保您的“@RenderSection("Head", false) 位于布局中的 @Scripts.Render("~/bundles/jquery") 下,如下所示:

@Scripts.Render("~/bundles/jquery")
@RenderSection("Head", false)

最后检查您的 BundleConfig 类是否有类似以下文件的代码:

 public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
}

关于MVC 升级后 Javascript 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34587482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com