我最近发现了jsp标签并使用它们来避免重复我的视图的常见部分.
所以在我的JSP视图中我有
<web-component:mytag>
<!-- HTML specific to that page -->
</web-component:mytag>
Run Code Online (Sandbox Code Playgroud)
在我的标签文件中,我得到了HTML <jsp:doBody/>.
我的问题是,如何测试是否<jsp:doBody/>为空,以便我可以放置默认的HTML内容?
就像是
<c:choose>
<c:when test="${!doBody.empty}">
<jsp:doBody/>
</c:when>
<c:otherwise>
<!-- My default HTML content here -->
</c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找正确的表达方式 doBody.empty
提前致谢.
我有一个click事件绑定在包含 Google 地图的元素上。当用户单击十字关闭地图上的信息窗口时,将触发单击事件并在整个 DOM 中传播。我想停止此事件传播,因此信息窗口关闭,但我的容器上没有引发单击事件。
Google Maps API 提供了一个closeclick在 InfoWindow 关闭时引发的事件,但是无法访问该事件(它不作为参数存在):
google.maps.event.addListener(infowindow, "closeclick", function() {
// The API function doesn't have the e parameter, I can't access closeclick
});
Run Code Online (Sandbox Code Playgroud)
由于我的容器无论如何都被绑定click,我什至不确定closeclick.stopPropagation()是否会起作用。所以我正在寻找一种方法来访问用户点击十字时谷歌地图引发的点击事件。当然,谷歌地图的html太混乱了,我无法访问跨DOM元素来向其添加事件监听器(它只是到处都是div,没有任何类)。
有什么建议么?
编辑:作为解决方法,我通过修改自己的代码并测试事件被容器捕获时来自何处来解决此问题:
container.addEventListener('click', function(ev) {
if (ev.target.src == 'https://maps.gstatic.com/mapfiles/api-3/images/mapcnt6.png') {
return false;
}
// the code I want to execute only when the click event doesn't come from the InfoWindow
});
Run Code Online (Sandbox Code Playgroud) 我正在寻找建议和反馈,因为我无法确定要走的路.
我正在构建HTML5表单,我希望它们尽可能简单易用.这就是为什么我总是使用label来解释在字段中输入的内容,并使用占位符作为具有良好格式的值的示例.
所以,我的代码总是如下:
<form>
<fieldset>
<p>
<label for="origin-field">Please enter your origin address</label>
<input type="text" name="origin" id="origin-field" placeholder="23th Street, New York City" required />
</p>
<p>
<label for="destination-field">Please enter you destination address</label>
<input type="text" name="destination" id="destination-field" placeholder="Ashbury Street, San Francisco" required />
</p>
</fieldset>
<p>
<input type="submit" />
</p>
</form>
Run Code Online (Sandbox Code Playgroud)
可以访问此代码,使用for属性将标签链接到输入,简而言之,它遵循最佳实践.它具有其他用户体验优势:如果用户单击输入然后分心,标签将始终显示在其旁边,并且可以轻松地提醒他们输入正在等待的信息.
但是,我的产品所有者和我的设计师非常希望我删除标签并使用占位符代替,所以代码就是
<form>
<fieldset>
<p>
<input type="text" name="origin" id="origin-field" placeholder="Origin address" required />
</p>
<p>
<input type="text" name="destination" id="destination-field" placeholder="Destination address" required />
</p>
</fieldset>
<p>
<input type="submit" />
</p>
</form> …Run Code Online (Sandbox Code Playgroud) forms ×1
google-maps ×1
html5 ×1
infowindow ×1
javascript ×1
jsp ×1
jsp-tags ×1
label ×1
placeholder ×1