在我的元素中,我遇到了在 wicket 类中获取 css 属性值的问题,假设我们有一些面板
public final class ExamplePanel extends Panel {
public ExamplePanel(String id) {
super(id);
add(new Label("someText", "hello"));
}}
这个文件的html文件是
<html xmlns:wicket>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>ExamplePanel</title>
<wicket:head>
<link href="panel.css" rel="stylesheet"/>
<script src="jquery.min.js"></script>
<script src="jquery-ui.min.js"></script>
</wicket:head>
</head>
<body>
<wicket:panel>
<div id="container" wicket:id="hello">
</div>
</wicket:panel>
</body>
和下面的CSS
#parentContainer{
width:500px;
height: 500px;
background:RGB(57,51,51);
position:relative;
}
例如,我需要获取 css 代码的值
public final class ExamplePanel extends Panel {
public ExamplePanel(String id) {
super(id);
Label label = new Label("someText", "hello");
add(label);
// draft code
//String height = label.getCssValue("height");
// String position = label.getcssvalue("position");
}}
或者从这个 div 获取 css 值的任何其他解决方案?
最佳答案
由于 CSS 应用于客户端,您唯一的机会是通过 JavaScript 获取值(Torr3nt 提到的 JQuery 方法是我所知道的最简单的方法)并使用 Ajax 将这些值发布回您的应用程序.
有关于如何从 JavaScript 调用 wicket 的描述 here .
关于java - 在 wicket 中获取 CSS 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11607039/