Javascript 如何在接收和查找特定类后隐藏元素?它';s jquery

Javascript 如何在接收和查找特定类后隐藏元素?它';s jquery,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,今天请帮我做以下几点: 我的1。步骤: <div id="htmlData"> <div class="col-md-12"> <div class="pull-left"> <h3>Report: <strong>Travel </strong></h3> <h3>Total Bookings:

今天请帮我做以下几点: 我的1。步骤:

<div id="htmlData">         
        <div class="col-md-12">
        <div class="pull-left">
           <h3>Report: <strong>Travel </strong></h3>
                <h3>Total Bookings: <strong>240</strong> | Customer Bookings: <strong>20</strong></h3>
                <p>The following report presents a graphical view of all travel booked.</p>
        </div>
        <div class="pull-right pdfhide" style="margin-right:0px !important;">
                <div class="col-md-6 pdfhide" style="margin-right:-0px !important;">
                                        <div class="input-group input-large date-picker input-daterange" data-date="10/11/2012" data-date-format="dd/mm/yyyy">
                                            <input type="text" class="form-control" name="from" value="<?php echo date("d/m/Y",strtotime("-1 month"));?>">
                                            <span class="input-group-addon pdfhide">
                                            to </span>
                                            <input type="text" class="form-control" name="to" value="<?php echo date("d/m/Y",strtotime("+1 day"));?>">
                                        </div>
                                        <!-- /input-group -->

                                    </div>                  
        </div>

        </div>
因此,朋友们,我只想注入
style=“display:none”
来查找具有类
“pdfhide”
的元素,然后在注入之后将其传递到printout\u html.php页面。请注意:当我将它们打印在printout_html.php页面上时,它不应显示这些隐藏元素。:)

感谢高级版,我知道那里的人都是非常聪明的程序员:)谁能帮我解决这些愚蠢的事情:

你可以使用jquery的
.hide()
函数

比如:
$('#htmlData').find('.pdfhide').hide()

更新后的代码应如下所示

                if($('#htmlData').find('.pdfhide').length != 0) {
                        $('#htmlData').find('.pdfhide').hide();
                        alert(htmlData);
                        $("#loader").show("slow");

                    $.ajax({

                        url: 'print_html.php',
                        type: 'POST',

                        data: {html_data: htmlData},//original....
                        success: function(data){
                            alert(data);
                        }, error: function() {
                            alert('Found error!');
                        }
                     });
                  } else {
                        alert('oh no');
                  }
试试这个:


$('#htmlData').find('.pdfhide').css(“显示”,“无”)

有两种方法可以尝试添加新类或

.css()

第一个你可以添加的类

$('#htmlData').find('.pdfhide').addClass('abcd')

第二次添加css将删除现有css

var asdf=$('#htmlData').find('.pdfhide')

$('#htmlData').find('.pdfhide').css('display','none')


另外,您有多个相同的类,因此可能会导致一些问题。

因为您有一个元素数组,所以请使用此

  $('#htmlData').find('.pdfhide').each(function (inde) {
  $(this).css( "display", "none" );
//Or use this
//$(this).attr("style","display:none");
});

我希望此帮助可以使用以下代码添加样式

$(".pdfhide").css("display","none");
但您已将pdfhide类添加到除输入元素之外的每个元素。父div它将隐藏所有作为子元素的元素,而不需要添加所有元素来隐藏所有元素

尝试运行此代码

 var htmlData = $('div').find('div.pdfhide').html();
        if(htmlData.length != 0) {
                        $('div').find('div.pdfhide').css('display','none');
                        console.log(htmlData);
                    } else {
                        alert('oh no');
                    }
                   $("#loader").show("slow");
                    $.ajax({
                        url: 'print_html.php',
                        type: 'POST',
                        data: {html_data: htmlData},
                        success: function(data){
                            alert(data);
                        }, error: function() {
                            alert('Found error!');
                        }
                    });
我认为您在发送htmlData时也有问题。所以请试试这个,我想它适合你。

试试这个- 将ID和样式显示给您的div,即

<div class="pull-right pdfhide" id="pdfhide" style="margin-right:0px !important;display:block">
 //Your code
 </div>

我希望它能对你有所帮助。

Bro我试过这个,但它对我不起作用。抱歉:(任何其他的想法我,它不起作用,因为我不想在这里隐藏()元素,而是将样式显示:无注入html代码,这样当我将html代码显示到下一页时,它会隐藏这些元素。隐藏()自动将display:none添加到具有
.pdfhide
类的元素中。您可以检查该元素并检查相同的元素…嗨,它只会在当前页面上隐藏该元素,而不是在print_html.php页面上,我需要一些解决方案,当发送数据到print_html.php页面时,我将哪个元素指定为display:none sho无法显示在print_html.phpdo中是否要使用显示属性隐藏元素您正在尝试发送哪些特定数据?
<div class="pull-right pdfhide" id="pdfhide" style="margin-right:0px !important;display:block">
 //Your code
 </div>
document.getElementById("pdfhide").style.display = "none";