0

我在 wordpress 网站上使用灵活地图插件。该插件有一个表单,允许用户输入他们的“发件人地址”以获取前往地图上显示位置的路线。该表单没有 ID 或类别(我无法添加)。

我希望用户能够在提交表单后打印方向,但我不希望在用户按下提交按钮显示方向之前显示打印按钮。

方向显示在表格中,所以我想我可以使用 JQuery 说当表格显示时,然后显示打印 div。

我在想它是这样的,但我不确定如何根据表格格式化它(因为表格没有 ID):

jQuery(document).ready(function($) {
 $('#idOfYourForm').on("submit", function () {
$('#print').show();
});
});

任何建议表示赞赏!

编辑这是按下方向提交按钮后生成的代码:

<div id="my-dir-div" style="float: left; direction: ltr;">
<form>
<p>
<input type="text" name="from">
<input type="submit" value="Get Directions">
</p>
</form>
<div jstcache="0">
<div class="adp-warnbox" jsdisplay="warnings.length" jstcache="1" style="display: none;">
<div class="warnbox-c2" jstcache="0"></div>
<div class="warnbox-c1" jstcache="0"></div>
<div class="warnbox-content" jscontent="$this" jsselect="warnings" jstcache="5"></div>
<div class="warnbox-c1" jstcache="0"></div>
<div class="warnbox-c2" jstcache="0"></div>
</div>
<div jseval="setupPanelStep(this, $waypointIndex)" jsvalues="$waypointIndex:0;" jsselect="legs[0].start_address" jstcache="2">
<table id="adp-placemark" class="adp-placemark" jstcache="0">
<tbody jstcache="0">
<tr jstcache="0">
<td jstcache="0">
<img jsvalues=".src:markerIconPaths[$waypointIndex]" jstcache="14" src="http://maps.gstatic.com/mapfiles/markers2/icon_greenA.png">
</td>
<td class="adp-text" jscontent="$this" jstcache="12">211 South Elson Street, Kirksville, MO 63501, USA</td>
</tr>
</tbody>
</table>
</div>
<div jsvalues="$legIndex:$index;" jsselect="legs" jstcache="3" jsinstance="*0">
<div class="adp-legal" jscontent="copyrights" jstcache="4">Map data ©2013 Google</div>
</div>
</div>
<div id="print">
<input id="print" class="printbtn" type="button" value="Print Directions" onclick="return pop_print()">
<script type="text/javascript">
function pop_print(){
w=window.open(null, 'Print_Page', 'scrollbars=yes');
w.document.write(jQuery('div#my-dir-div').html());
w.document.close();
w.print();
}
</script>
</div>
4

1 回答 1

0

我想你可以试试这个(只有当adp-placemark页面上有带有 id 的表时才显示它)

$(function(){
    if($('#my-dir-div table#adp-placemark').length) $('#print').show();
});

或者,这个

$(function(){
    if($('#my-dir-div table#adp-placemark td.adp-text').length) $('#print').show();
});
于 2013-05-02T21:49:17.520 回答