如何在 MVC 中隐藏一个 div 并在按钮单击事件上显示另一个
how to hide one div and display another on button click event in MVC
这是我的 jquery 和 div 我想隐藏 tblMain 并使 tblmainalt 可见
$("btnUpdate").click(function() {
alert("button");
$("tblMain").hide();
$("tblMainAlt").show();
});
<div id="tblMainAlt" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;">
<div id="tblMain" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;">
在 tblMainAlt 中设置显示:none 样式因为第一次加载页面所以隐藏 div。
我已经添加了示例代码,您可以尝试一下。
JQuery:-
$("#btnUpdate").click(function () {
alert("button");
$("#tblMain").hide();
$("#tblMainAlt").show();
});
<div id="tblMainAlt" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;display: none;">
<div id="tblMain" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;">
这是因为您使用了错误的选择器。您必须使用 ID
或 CLASS
选择器。看到你 HTML,请用我的 jQuery 替换你的 jQuery,它将起作用。
$("#btnUpdate").click(function() {
alert("button"); // Remove this line if it worked
$("#tblMain").hide();
$("#tblMainAlt").show();
});
这是我的 jquery 和 div 我想隐藏 tblMain 并使 tblmainalt 可见
$("btnUpdate").click(function() {
alert("button");
$("tblMain").hide();
$("tblMainAlt").show();
});
<div id="tblMainAlt" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;">
<div id="tblMain" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;">
在 tblMainAlt 中设置显示:none 样式因为第一次加载页面所以隐藏 div。
我已经添加了示例代码,您可以尝试一下。
JQuery:-
$("#btnUpdate").click(function () {
alert("button");
$("#tblMain").hide();
$("#tblMainAlt").show();
});
<div id="tblMainAlt" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;display: none;">
<div id="tblMain" class="tableSpaced" style="width:auto;height:100%;margin-left:25px;">
这是因为您使用了错误的选择器。您必须使用 ID
或 CLASS
选择器。看到你 HTML,请用我的 jQuery 替换你的 jQuery,它将起作用。
$("#btnUpdate").click(function() {
alert("button"); // Remove this line if it worked
$("#tblMain").hide();
$("#tblMainAlt").show();
});