我有一个 XML 文件,它存储使用 JSP 页面中包含的 Java 哈希表显示的内容(它目前使用我现在知道的 scriplets 是不好的做法)
随着 XML 内容量的增加,我需要开始分批显示它,例如5 <sliceContent>
div,然后为用户提供单击下一步的选项。我最后有“下一个”div。我当然还必须添加一个“上一个”选项。
我不确定我在找什么,我找到了一些帖子,例如 this post但我真的听不懂。这可以单独通过 CSS 完成还是我需要用 Java 实现?
再次感谢您的任何建议。
编辑 我已经用 CSS 和 Javascript 重新标记了它,因为有人告诉我这是我需要的。
我的XML(内容可以扩展到几个段落)
<slice><sliceContent> Content element 1 </sliceContent></slice>
<slice><sliceContent> Content element 2 </sliceContent></slice>
<slice><sliceContent> Content element 3 </sliceContent></slice>
我的 Java(包含在 JSP 页面中)
<div class='result-container'>
<ul class="menu menu-style">
<li>
<a href="javascript:;">Concept for <%=keywords%></a>
<ul xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" class="menu menu-style">
<li>
<a href="javascript:;">
<span>Show Concept</span>
</a>
<ul class="wer">
<%
String testContent = contentPara;
String startTag = "sliceXML\">";
String endTag = "<";
String xmlMatch = null;
String hashMatch = null;
int startPosition = testContent.indexOf(startTag);
if(startPosition >1)
{
int subStringIndex = startPosition + startTag.length();
int endPosition = testContent.indexOf(endTag, subStringIndex);
if(endPosition >= startPosition)
{
xmlMatch = testContent.substring(subStringIndex, endPosition);
}
if(xmlMatch == null)
{
out.println("No concept matches for your query!" );
}
else
{
Hashtable<String, String> table = new Hashtable<String, String>();
(hash table links here)
try{
FileInputStream fstream = new FileInputStream(table.get(xmlMatch));
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
out.println (strLine);
}
//Close the input stream
in.close();
}
catch (Exception e)
{
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
<li>
<div class="next-div">
<a class="next">Next<img height="10px" src="images/more.png" />
</a>
</div>
</li>
</ul>
</li>
</li>
</ul>
</div>
最佳答案
您可以使用 javascript 执行此操作:
<script type="text/javascript" language="JavaScript">
function showContent(){
document.getElementById('showContent').innerHTML = "Here is the text we want to show";
}
</script>
HTML:
<a href="#" onclick="showContent()">showContent</a>
<div id="showContent"></div>
关于javascript - CSS Javascript 在用户点击时显示下一个/上一个 Div 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12784193/