所以我正在制作一个“ Web程序”(您将html文件下载到您的PC或电话中,然后从那里使用它。)我的问题是我做了一个下拉菜单按钮,并在其中放了一张桌子您可以编辑的单元格我希望仅在单击它时关闭它,但是当我单击文本框或按钮时,它在我身上关闭。有人可以帮我吗? 我的代码:
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
/* Dropdown Button */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
/* Dropdown button on hover & focus */
.dropbtn:hover,
.dropbtn:focus {
background-color: #2980B9;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd
}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {
display: block;
}
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Edit Word List!</button>
<div id="myDropdown" class="dropdown-content">
<!--- makes the acctuale list--->
<table>
<tr id="1">
<td>
1 <input type="text" id="word1">
</td>
<td>
11 <input type="text" id="word11">
</td>
</tr>
<tr id="2">
<td>
2 <input type="text" id="word2">
</td>
<td>
12 <input type="text" id="word12">
</td>
</tr>
<tr id="3">
<td>
3 <input type="text" id="word3">
</td>
<td>
13 <input type="text" id="word13">
</td>
</tr>
<tr id="4">
<td>
4 <input type="text" id="word4">
</td>
<td>
14 <input type="text" id="word14">
</td>
</tr>
<tr id="5">
<td>
5 <input type="text" id="word5">
</td>
<td>
15 <input type="text" id="word15">
</td>
</tr>
<tr id="6">
<td>
6 <input type="text" id="word6">
</td>
<td>
16 <input type="text" id="word16">
</td>
</tr>
<tr id="7">
<td>
7 <input type="text" id="word7">
</td>
<td>
17 <input type="text" id="word17">
</td>
</tr>
<tr id="8">
<td>
8 <input type="text" id="word8">
</td>
<td>
18 <input type="text" id="word18">
</td>
</tr>
<tr id="9">
<td>
9 <input type="text" id="word9">
</td>
<td>
19 <input type="text" id="word19">
</td>
</tr>
<tr id="10">
<td>
10 <input type="text" id="word10">
</td>
<td>
20 <input type="text" id="word20">
</td>
</tr>
</table>
</div>
</div>
我输入的代码仅用于按钮。
答案 0 :(得分:0)
没关系,它显然没有问题。