【发布时间】:2012-03-15 16:09:47
【问题描述】:
我在使用 jQuery 验证插件的 Google 地图信息窗口中有一个 HTML 表单。当它显示错误消息(我已将它们移动到表单输入下)时,带有表单的 div 会溢出信息窗口。
我已经阅读了对类似问题的回复,但我还没有解决任何这些解决方案。
HTML 表单:
<div id="formDiv">
<form action="addRow.php" method="post"id="htmlForm">
<fieldset>
<p id="contactP">
<label for="contact">Email:</label>
<input type="text" name="contact" id="contact"/> <br/>
</p>
<p id="dateP">
<label for="datepicker">Date:</label>
<input type="text" name="date" id="datepicker"/> <br/>
</p>
<p id="latP">
<label for="lat">Latitude:</label>
<input type="text" name="lat" id="lat" class="location"/> <br/>'+
</p>
<p id="lngP">
<label for="lng">Longitude:</label>
<input type="text" name="lng" id="lng" class="location"/> <br/>
</p>
<p id="descP">
<label for="desc" id="dos">Description of Sighting:</label> <br/>
<textarea name="desc" id="desc"></textarea><br/>
</p>
<input type="submit" class="button" id="submitBtn" value="Post Sighting!" onclick="postSighting();"/>'+
<p class="clear"></p>'+
</fieldset></form></div>
;
jQuery:
$('#htmlForm').validate({
rules: {
contact: {required:true, email:true},
date: {required:true},
lat: {required:true},
lng: {required:true},
desc: {required:true},
},
messages: {
desc: 'Please be descriptive!'
},
errorPlacement: function(error, element) {
error.appendTo($('#' + element.attr('id') + 'P'));
if (element.attr('id') == 'desc') {
error.css({
text_align: 'center',
color: 'red',
padding: 45,
});
} else {
error.css({
color: 'red',
padding: 10,
margin:0,
})};
}
});
【问题讨论】:
-
为什么这个标签是 google-maps-api-3?
-
这就是重点——它是谷歌地图信息窗口内的 HTML 表单。信息窗口不会重新调整大小以适应包含插入的错误消息的 div。
-
实时代码的链接将非常有价值。您的所有代码都与 Maps API 无关。除非您提供代码链接并提供更多详细信息,否则您可能不会得到答案。
-
JsFiddle 似乎没有运行验证代码——该部分在我端正确运行(ie9 & chrome)。 jsfiddle.net/rhewitt/gqa6k/1
标签: css jquery google-maps-api-3