[英]Showing HTML content just after login in ASP.Net MVC
有什么方法可以从 JS function 调用 HTML 吗? 下面是代码参考: ASP.Net MVC 中的登录方法是这样实现的:
<div>
<button id = "btnSubmit" name ="btnSubmit" class="pop-submit" value="submit" type = "submit" onclick="loginl();">sign in </button>
<script type="text/javescript">
function loginl(){
$("#inprogress").attr("style","display:block";height:50px;width:100%;");
// HTML call to show message from here
document.forms["formlogin"].submit();
return true;
}
</script>
点击登录,也就是提交之前,我想实现一段HTML:
留言:感谢您与我们联系。 请访问我们的新网址(此处 url 将 go)。 以下是最近的变化:
- 项目1
- 项目2
有没有最简单的方法来实现这一目标? 我正在尝试使用“警报”或“提示”。 但是,似乎没有在其中包含 HTML/CSHTML 的规定。
这就是我正在尝试做的事情:
<script type="text/javescript">
function loginl(){
$("#inprogress").attr("style","display:block";height:50px;width:100%;");
alert('message' + $(this).html("DiLogBox")); //can I not do something like this?
document.forms["formlogin"].submit();
return true;
}
</script>
那么我的 HTML 将是:
<div id = "DiLogBox">
......
</div>
这里没有验证。 只需显示消息。
好吧,您可以使用弹出框来帮助您。 而已
我假设您真正想要实现的是在 window 之类的模态中显示一条消息。 这里有两个选项:Vanilla JS 或使用一些第三方,如jQuery modal 。 这是另一篇关于如何使用 Vanilla JS 实现它的文章。
然后,您可以将事件侦听器添加到表单并阻止发送它,直到用户关闭模式。
这是一个简单的例子:
// Get the modal var modal = document.getElementById("myModal"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; var showModal = function(){ modal.style.display = "block"; } var hideModal = function(){ modal.style.display = "none"; } //Prevent the form to submit document.forms[0].addEventListener("submit", function(e){ var form = this; e.preventDefault(); showModal(); span.addEventListener("click", function(){ hideModal(); form.submit(); alert("form submitted"); }); });
/* The Modal (background) */.modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ } /* Modal Content/Box */.modal-content { background-color: #fefefe; margin: 15% auto; /* 15% from the top and centered */ padding: 20px; border: 1px solid #888; width: 80%; /* Could be more or less, depending on screen size */ } /* The Close Button */.close { color: #aaa; float: right; font-size: 28px; font-weight: bold; }.close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; }
<form> <label for="my-name">Name</label> <input id="my-name" type="text" /> <button type="submit">Submit</button> </form> <;-- The Modal --> <div id="myModal" class="modal"> <.-- Modal content --> <div class="modal-content"> <span class="close">×.</span> <p>Some text in the Modal..</p> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.