【问题标题】:PHP or JQuery or CSS (in wordpress)- Show Div when Table data is displayedPHP 或 JQuery 或 CSS(在 wordpress 中)- 显示表数据时显示 Div
【发布时间】:2013-05-03 05:49:17
【问题描述】:

我在 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>

【问题讨论】:

    标签: php jquery css wordpress


    【解决方案1】:

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

    $(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();
    });
    

    【讨论】:

    • 我都试过了,直接插入到页面中,如 jQuery(document).ready(function($) { $(function(){ if($('#my-dir-div table#adp -placemark td.adp-text').length) $('#print').show(); }); });但都没有用。
    • 其实$(function(){...})jQuery(document).ready()的简写,所以用一个。
    • 您可以将代码if($('#my-dir-div table#adp-placemark').length) $('#print').show(); 保留在function pop_print(){...} 下方的&lt;script&gt; 中。
    • 我从页面中删除了脚本并像这样将其添加到函数 pop_print 中,但它不起作用..也许我做错了什么。
    • pop_print 是一个插件,它在 div 下: '

      '
    猜你喜欢
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多