简体   繁体   English

我如何实现javascript函数以仅打印内容 <div class=“clear TmarginXlg paddingLg”> … </div>

[英]how can i implement a javascript function to just print the content of <div class=“clear TmarginXlg paddingLg”>…</div>

<div class="unit size3of5">
                        <div class="letterBody paddingLg LmarginXlg">

                <?php 
                    if (strpos(strtolower($philosophies[0][bg_img]), '.png')) $remote = false;
                        else $remote = true;

                    ?>
                            <img src="<?php echo base_path().$directory; ?>/img/logo.png" width="100" class="floatL" alt="..." />
                            <div class="salonLogo floatR">
                                <img id="salonLogo" src="<?php echo base_path().$directory;?>/img/clientToolBox/salonLogo.jpg" class="" alt="..." />
                                <span class="miniFog">&nbsp;</span>
                            </div>
                            <div class="clear TmarginXlg paddingLg">
                                <p class="upperC paddingLg BpaddingSm" id="PpressName"><?php echo t($webform['components'][4]['value']); ?></p>
                                <p class="paddingLg BpaddingSm" id="PpressLocation"><?php echo t($webform['components'][5]['value']); ?></p>
                                <p class="paddingLg BpaddingSm" id="PpressDesc"><?php echo t($webform['components'][6]['value']); ?></p>
                                <p class="paddingLg BpaddingSm" id="PpressContactName"><?php echo t($webform['components'][7]['value']); ?></p>
                                <p class="floatR paddingLg BmarginXlg" id="PpressContactNum"><?php echo t($webform['components'][8]['value']); ?></p>
                                <p class="BmarginXlg">&nbsp;</p>
                            </div>
                        </div>
                    </div>

Would jQuery's $.html() function give you the result you're looking for? jQuery的$ .html()函数会为您提供所需的结果吗?

http://api.jquery.com/html/ http://api.jquery.com/html/

If you don't mind using jquery , you could use: 如果您不介意使用jquery ,则可以使用:

$(".clear.TmarginXlg.paddingLg").text();

That would return you all the text inside the div you mentioned and all of its children's text. 那将返回您提到的div内的所有文本及其所有子文本。

You could do this with jquery or any other javascript library, unfortunately I'm only familiar with jquery. 您可以使用jquery或任何其他javascript库来执行此操作,但是不幸的是,我只熟悉jquery。

If you don't want to use a javascript library, you would have to iterate over the children of that DIV and concatenate their text nodes manually. 如果您不想使用javascript库,则必须遍历该DIV的子级并手动连接其文本节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM