在我的项目中,我遇到了一个问题,从类中调用javascript代码
在wicket中呈现html.假设我们有一个类ExamplePanel,其中包含以下wicket面板代码
public final class ExamplePanel extends Panel {
public ExamplePanel(String id) {
super(id);
add(new Label("someText", "hello"));
}}
Run Code Online (Sandbox Code Playgroud)
和html文件'ExamplePanel'
<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="parentContainer">
<div id="box" wicket:id="someText"></div>
</div>
</wicket:panel>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
并遵循css
#box{
background: #f0f0f0;
width: 50px;
height: 50px;
position: absolute;
top: 200px;
left: 200px;
font-size: 1.5em;
word-wrap: break-word;
}
#parentContainer{
width:500px;
height: 500px;
background:RGB(57,51,51);
position:relative;
}
Run Code Online (Sandbox Code Playgroud)
从这段代码我们在parentContainer div中有框,我需要在初始化ExamplePanel类时将位置坐标传递给框,例如:
public ExamplePanel(String id) { …
Run Code Online (Sandbox Code Playgroud)