在这篇文章中,我们将为您详细介绍JavaScriptmodal无法打开的内容,并且讨论关于javascript打不开的相关问题。此外,我们还会涉及一些关于angular封装modal,一个modal,
在这篇文章中,我们将为您详细介绍JavaScript modal 无法打开的内容,并且讨论关于javascript打不开的相关问题。此外,我们还会涉及一些关于angular 封装 modal,一个 modal,多次使用、antd modal on modal 点击未打开、Bootstrap Modal Event Not Fired When Modal is Shown/Hidden、Bootstrap Modal 加载页面本身包含另一个 Modal的知识,以帮助您更全面地了解这个主题。
本文目录一览:- JavaScript modal 无法打开(javascript打不开)
- angular 封装 modal,一个 modal,多次使用
- antd modal on modal 点击未打开
- Bootstrap Modal Event Not Fired When Modal is Shown/Hidden
- Bootstrap Modal 加载页面本身包含另一个 Modal
JavaScript modal 无法打开(javascript打不开)
如何解决JavaScript modal 无法打开
我正在制作一个笔记应用程序,让您可以选择在单击按钮时以模式查看所述笔记。注释和模态的 HTML 由事件侦听器动态生成。有两种方法可以关闭模态,通过单击“X”按钮或单击模态外部。每当只生成一个音符时,该程序就具有完整的功能,但是一旦我生成了第二个音符,代码就会崩溃。一旦发生这种情况,我只能打开生成的第一个音符的模式,但不能关闭它。然后第二个就打不开了。我该如何解决这个问题?
class Input {
constructor(note) {
this.note = note;
}
}
class UI {
addNote(input) {
// Get table body below form
const content = document.querySelector(".content");
// Create tr element
const row = document.createElement("tr");
// Insert new HTML into div
row.innerHTML = `
<td>
${input.note}
<br><br>
<button class="modalBtn">View Note</button>
</td>
`;
content.appendChild(row);
// Event listener to make modal
document.querySelector(".modalBtn").addEventListener("click",function(e) {
// Get container div
const container = document.querySelector(".container");
// Create div
const div = document.createElement("div");
// Assign class to it
div.className = "modal";
// Insert HTML into div
div.innerHTML = `
<div class="modal-content">
<span class="closeBtn">×</span>
<div>
<p>${input.note}</p>
</div>
</div>
`;
// Append the new div to the container div
container.appendChild(div);
// Get modal
const modal = document.querySelector(".modal");
// Event listener to close modal when "x" is clicked
document.querySelector(".closeBtn").addEventListener("click",function() {
container.removeChild(modal);
});
// Event listener to close when the window outside the modal is clicked
window.addEventListener("click",function(e) {
if (e.target === modal) {
container.removeChild(modal);
}
});
});
}
// Clear input field
clearinput() {
note.value = "";
}
}
// Event listener for addNote
document.getElementById("note-form").addEventListener("submit",function(e) {
// Get form value
const note = document.getElementById("note").value;
// Instantiate note
const input = new Input(note);
// Instantiate UI
const ui = new UI();
// Validate form (make sure input is filled)
if (note === "") {
// Error alert
alert("Please fill in text field!");
}
else {
// Add note
ui.addNote(input);
// Clear input field
ui.clearinput();
}
e.preventDefault();
});
h5 {
color: green;
}
.modal {
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0.5);
}
.modal-content {
background-color: #fff;
margin: 20% auto;
padding: 30px;
width: 70%;
Box-shadow: 0 5px 8px 0 rgba(0,0.2),0 7px 20px 0 rgba(0,0.17);
animation-name: modalopen;
animation-direction: 1s;
}
.closeBtn {
color: #aaa;
/* float: right; */
font-size: 30px;
margin-bottom: 1rem;
padding-bottom: 1rem;
}
.closeBtn:hover,.closeBtnBtn:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.closeBtn + div {
margin-top: 2rem;
}
@keyframes modalopen {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css" integrity="sha512-5fsy+3xG8N/1PV5MIJz9ZsWpkltijBI48gBzQ/Z2eVATePGHOkMIn+xTDHIfTZFVb9GMpflF2wOWItqxAP2oLQ==" crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
<title>Note Taker</title>
</head>
<body>
<div class="container">
<h1>Note Taker</h1>
<h5>Add A New Note:</h5>
<form id="note-form">
<div>
<label>Note:</label>
<textarea name="Note" id="note" class="u-full-width"> </textarea>
</div>
<div>
<button type="submit" class="button-primary">Add Note</button>
</div>
</form>
<table>
<tbody class="content"></tbody>
</table>
</div>
<script src="app.js"></script>
</body>
</html>
解决方法
拳头..我喜欢你的语法!!迄今为止我见过的最好的!第二..你做一个一般查询选择器,不要单独处理它们。这会是个问题吗?
编辑: 由于某些原因,我将重新制定我的答案..
document.querySelector(''class'')
返回一个带有 DOM 元素引用的 Html-Collection,其中包含指定的 html 类,应单独处理。
angular 封装 modal,一个 modal,多次使用
js:
app.directive("modal", ["$timeout", function ($timeout) {
return {
restrict: "AE",
templateUrl: "/template/modal.html",
scope: {
modalData: "=",
sureCallback: "&",
clearSearchTerm: "&"
},
link: function (scope, element) {
var modalHeaderHeight, modalFooterHeight, firstShow = true;
$("body").on("show.bs.modal", "#" + scope.modalData.modalId, function (e) {
if ($(".modal-dialog").length > 1) {
$(element).find(".modal-dialog").css("margin", $(".modal-dialog").eq(0).css("margin"));
}
});
$("body").on("shown.bs.modal", "#" + scope.modalData.modalId, function (e) {
$.isFunction(scope.modalData.callback) && scope.modalData.callback();
if (firstShow) {
firstShow = false;
} else {
return;
}
modalHeaderHeight = $(element).find(".modal-header").outerHeight(false);
modalFooterHeight = $(element).find(".modal-footer").outerHeight(false);
$(element).find(".modal-body").css({
maxHeight: "calc(100vh - " + (modalHeaderHeight + modalFooterHeight + 60) + "px )",
overflowY: "auto"
});
});
$("body").on("hide.bs.modal", "#" + scope.modalData.modalId, function (e) {
if ($.isFunction(scope.clearSearchTerm)) {
scope.clearSearchTerm();
}
});
$(element).on("click", ":not(.md-select-menu-container)", function (event) {
$(".md-select-backdrop").click();
event.stopPropagation();
});
}
};
}]).service("modal", ["$timeout", "$compile", function ($timeout, $compile) {
this.show = function (selector, scope, callback) {
angular.element("#" + selector).modal("show");
if ($.isFunction(callback)) {
angular.element("#" + selector).off("shown.bs.modal");
angular.element("#" + selector).on("shown.bs.modal", function (e) {
$.isFunction(callback) && callback();
scope && !scope.
});
}
};
this.replaceModalBody = function (modalSelector, modalBodyselector, scope) {
var modalBody = angular.element(modalBodyselector).html();
modalBody = $compile(modalBody)(scope);
angular.element(modalSelector).find(".modal-body").html(modalBody);
};
this.replaceModalHeader = function (modalSelector, modalHeaderselector, scope) {
var modalHeader = angular.element(modalHeaderselector).html();
modalHeader = $compile(modalHeader)(scope);
angular.element(modalSelector).find(".modal-header").html(modalHeader);
};
}]);
template:
<divid="{{modalData.modalId}}">
<div>
<div>
<div>
<button type="button"data-dismiss="modal">
<span aria-hidden="true">×</span>
<span>Close</span>
</button>
<h4ng-bind="modalData.modalTitle"></h4>
</div>
<divng-bind-html="modalData.modalBodyContent|trusted_html"></div>
<div>
<md-button md-colors="{color: ''grey-500''}" data-dismiss="modal">Cancel</md-button>
<md-button md-colors="{color: ''green-500''}" data-dismiss="modal" ng-click="sureCallback()">Submit</md-button>
</div>
</div>
</div>
</div>
antd modal on modal 点击未打开
如何解决antd modal on modal 点击未打开
我有一个 antd 模态,如下面的代码所示,现在当我选择 Create Manual
并点击 Next
,I want to close this modal and open another Modal2
但另一个模态没有得到点击下一步后打开。
这是我的代码。 ( CodesandBox 现场演示 - link )
请提出一种解决方法来生成他的第二个模态。谢谢
import React,{ useState } from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Modal,Button,Radio } from "antd";
const App = () => {
const [isModalVisible,setIsModalVisible] = useState(false);
const [selecTradio,setselecTradio] = useState("preselect");
const showModal = () => {
setIsModalVisible(true);
};
const select = (e) => {
// you can save the value in here
setselecTradio(e.target.value);
console.log(e.target.value);
};
function modalclick() {
if (selecTradio === "preselect") {
alert("pre-select");
} else {
//---------------> UNABLE TO OPEN ANOTHER MODAL HERE <-------------------------------------
<Modal title="Create Test Suite" visible={isModalVisible}>
MODAL 2 COMES HERE
</Modal>;
alert("manual");
}
}
return (
<>
<Button type="primary" style={{ float: "right" }} onClick={showModal}>
Create Test Suite
</Button>
<Modal
title="Create Test Suite"
visible={isModalVisible}
footer={[
<Button key="cancel" onClick={() => setIsModalVisible(false)}>
Cancel
</Button>,<Button type="primary" key="next" onClick={modalclick}>
Next
</Button>
]}
>
<Radio.Group
defaultValue="preselect"
buttononChange={(e) => {
select(e);
}}
>
<Radio value="preselect">Create from Preselect</Radio>
<Radio value="manual">Create Manual</Radio>
</Radio.Group>
</Modal>
</>
);
};
ReactDOM.render(<App />,document.getElementById("container"));
解决方法
要显示模态 2,您可以使用 useState 钩子 或 useRef 钩子。在这两种方法中,您首先需要将此模态 2 放入“应用程序”的返回。
useState 方式:只需使用 state 来控制可见性,就像您在 modal 1 中所做的那样,很简单。
useRef 方式:这有点复杂。您需要在模态组件内部使用 useImperativeHandle,并创建一个函数(也在内部)来控制可见性。因此,在您的页面中,您只需调用组件内部的函数即可显示模态。使用这种方法,可见性状态控制的逻辑离开页面,进入组件。
Bootstrap Modal Event Not Fired When Modal is Shown/Hidden
问题描述
使用jquery(3.2.1)。
Bootstrap(v4-alpha)的Modal中,如果Modal存在.fade那么shown.bs.modal以及hidden.bs.modal事件的回调函数不会被正常触发。
但是show.bs.modal以及hide.bs.modal两个事件的触发是正常的。
这两种事件的区别在于immediately和wait for CSS transitions to complete。
解决方法
在设置事件监听器之前动态添加.fadeclass:
$ -> registerModal = $(''#registerModal'') registerModal.addClass(''fade'') registerModal.on(''hidden.bs.modal'', -> $(this).find(''input'').val('''') )
以上就是Bootstrap Modal Event Not Fired When Modal is Shown/Hidden的详细内容,更多请关注php中文网其它相关文章!
Bootstrap Modal 加载页面本身包含另一个 Modal
如何解决Bootstrap Modal 加载页面本身包含另一个 Modal
我是 Bootstrap 的新手,对以下描述的功能有疑问: 我有第 1 页通过按钮打开引导模式。
<button type="button"data-toggle="modal" data-target="#exampleModal" data-modal-url="./test2.html">Modal Launch</button>
<divid="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static">
<divrole="document">
<div>
<div>
<h5id="exampleModalLabel">Example Modal</h5>
<button type="button"data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button>
</div>
<div>
...
</div>
<div>
<button type="button"data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$(''#exampleModal'').on(''show.bs.modal'',function (event) {
var src = $(this);
var modalUrl = src.data(''modal-url'');
src.find(''.modal-body'').load(modalUrl);
});
所以当我点击按钮引导模式弹出。我的问题在这里,现在是否可以为这个例子加载的页面说 test2.html 有自己的模式弹出功能? 我本质上想看到的是,是否有可能让模态加载一个页面,然后有按钮打开另一个模态来加载页面。然后最终使用 jQuery UI 之类的东西独立地拖动它们。
关于JavaScript modal 无法打开和javascript打不开的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于angular 封装 modal,一个 modal,多次使用、antd modal on modal 点击未打开、Bootstrap Modal Event Not Fired When Modal is Shown/Hidden、Bootstrap Modal 加载页面本身包含另一个 Modal的相关信息,请在本站寻找。
本文标签: