简体   繁体   English

跨度标记和嵌套跨度标记中的文本未显示

[英]Text in span tag and nested span tag not showing

I previously asked a similar question, but I did more research and found the more specific issue.我之前问过一个类似的问题,但我做了更多的研究,发现了更具体的问题。 I want to show text inside the span tag so that the div elements also inside it (which each has a checkbox) show up on the screen.我想在 span 标签内显示文本,以便其中的 div 元素(每个都有一个复选框)显示在屏幕上。

I tried adding a test image inside both the first and second span tag and it shows on the screen.我尝试在第一个和第二个 span 标签内添加一个测试图像,它显示在屏幕上。 But the text in both is not showing.但是两者中的文字都没有显示。 It should show up as "Countries + " in the checkbox-div box.它应该在checkbox-div框中显示为“Countries + ”。 When I put the image inside location-div the image does not display.当我将图像放入location-div时,图像不会显示。 The only thing that shows up is the button-like "Clear" reset element.唯一出现的是类似按钮的“清除”重置元素。 As in this picture: button-like element with "Clear" label inside checkbox-div bordered box , despite it showing in the running code snippet.如下图所示:带有“Clear”label 的按钮状元素位于 checkbox-div 边框框内,尽管它显示在正在运行的代码片段中。

I also tried adding style='display:block' inside all span tags.我还尝试在所有跨度标签中添加style='display:block' Then I tried adding that inside only the inner span tags as an answer to a question suggested, but it didn't work either.然后我尝试仅在内部跨度标签内添加它作为对建议问题的回答,但它也不起作用。

 function expand(element) { var list = element.nextElementSibling; var symbol = element.firstElementChild; if (list.style.display == 'block') { list.style.display = 'none'; symbol.innerHTML = '+'; } else { list.style.display = 'block'; symbol.innerHTML = '−'; } }
 #checkbox-div { max-height: 500px; overflow-y: auto; overflow-x: hidden; width: 200px; border: 1px solid #cccccc; padding: 2px; float: left; }.location-div { margin-left: 10px; display: none; } label { position: relative; margin-left: -20px; padding-right: 20px; left: 20px; }.expand { display: block; cursor: pointer; }.expand-symbol { font-weight: bold; }
 <div id='checkbox-div'> <form id='location-form' action="javascript:void(0);"> <span class='expand' onclick='expand(this)'>Countries <span class='expand-symbol'>+</span> </span> <.-- begin long line --> <div class='location-div'> <input type='checkbox' id='Albania' class='location-checkbox'><label for='Albania'>Albania</label> <br> <input type='checkbox' id='Algeria' class='location-checkbox'><label for='Algeria'>Algeria</label> <br> <!-- Etc. other countries --> <br> <input type='checkbox' id='Zimbabwe' class='location-checkbox'><label for='Zimbabwe'>Zimbabwe</label> <br> </div><input type='reset' value='Clear'> <!-- end long line --> </form> </div>

There is that very long line with line breaks because it is created in a for loop and with echo's in php before and after the loop, I added the paragraph spaces so it's easier to read.有很长的行带有换行符,因为它是在 for 循环中创建的,并且在循环前后在 php 中带有回声,我添加了段落空格,以便于阅读。

The expand function that once the "Countries + " is clicked, should show all the checkboxes underneath "Countries - ".单击“Countries + ”后展开的 function 应显示“Countries - ”下方的所有复选框。 This function works on another page that I tested, but I haven't been able to test it on the page I'm working on yet since "Countries + " doesn't show, despite it working in this code snippet.这个 function 可以在我测试的另一个页面上工作,但是我还不能在我正在处理的页面上测试它,因为“Countries + ”没有显示,尽管它在这个代码片段中工作。

nextSibling returns any next text node, comment node, or element node, thanks to Cbroe who pointed that out in the comments. nextSibling 返回任何下一个文本节点、评论节点或元素节点,感谢 Cbroe 在评论中指出了这一点。 I changed it to nextElementSibling to only get the next element.我将其更改为 nextElementSibling 以仅获取下一个元素。

Also thanks to Dionys who made me realize it had to do with some css hiding the expand.还要感谢 Dionys 让我意识到这与一些隐藏扩展的 css 有关。 My body css was originally like so:我的身体css原本是这样的:

body{
    min-width: 1010px;
    font-size: 0px;
    font-family: Arial, Sans-Serif;
    margin-left: 6px;
}

When I removed min-width: 1010px;当我删除min-width: 1010px; the text in the span showed up now.跨度中的文本现在出现了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM