domHtml += "<div class=\"PopupWindow_end\" onclick=\"changeQdgDetail(this, "+data.ccssbh+")\" >" + " <span>" + "展开详情" +" " +"▼"+ "</span>" + "</div>"+ "<div id='" + data.ccssbh + "' class='pop' name='myPop' style='height: 300px;width: 340px; position: absolute;display: none;background: white;overflow: scroll;z-index: 999;right: -2px;bottom: -300px'></div>"; 如果点击changeQdgDetail()后下拉弹框并把展开详情改成收回,点击时可收缩弹窗的拼接代码,用if语句编写
时间: 2024-03-12 11:48:07 浏览: 69
jquery+html实现轮播图-代码
您可以尝试使用以下的代码来实现您的需求:
```
let domHtml = "<div class=\"PopupWindow_end\" onclick=\"changeQdgDetail(this, "+data.ccssbh+")\" >" +
" <span>" + (isPopupOpen ? "收回详情" : "展开详情") +" " + (isPopupOpen ? "▲" : "▼") + "</span>" +
"</div>" +
"<div id='" + data.ccssbh + "' class='pop' name='myPop' style='height: 300px;width: 340px; position: absolute;display: " + (isPopupOpen ? "block" : "none") + ";background: white;overflow: scroll;z-index: 999;right: -2px;bottom: -300px'></div>";
// where isPopupOpen is a boolean variable that indicates whether the popup is open or not
function changeQdgDetail(element, id) {
let popup = document.getElementById(id);
let span = element.querySelector("span");
if (popup.style.display === "none") {
popup.style.display = "block";
span.textContent = "收回详情 ▲";
isPopupOpen = true;
} else {
popup.style.display = "none";
span.textContent = "展开详情 ▼";
isPopupOpen = false;
}
}
```
这段代码使用了一个名为 `isPopupOpen` 的布尔变量来跟踪弹出窗口是否已打开。在 `domHtml` 变量中,我们使用三元运算符来根据该变量的状态来设置展开/收回详情的文本和箭头符号。在 `changeQdgDetail` 函数中,我们检查弹出窗口的当前状态,并根据需要更新文本和箭头符号,并将 `isPopupOpen` 变量相应地设置为 `true` 或 `false`。
阅读全文