[英]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.