0

我正在尝试从从外部 url 加载的 js 小部件中隐藏所有不包含字符串“Marc”的表行。

<script type="text/javascript">
  id = "ki1120mmvd";
  name = "schedules";
  document.write(unescape("%3Cscript src='http://healcode.com/javascripts/hc_widget.js' type='text/javascript'%3E%3C/script%3E"));
</script>

我已经能够使用类 id 或属性使用 css 隐藏表行中的一些元素,但看起来我需要 js/jquery/php 来完全消除行,而我发现的所有内容都不起作用。

这是我获取代码的链接: http ://www.funkydoor.com/studio_polk_street.html

这是我使用它的方式:http: //www.marcmatisyoga.com/schedule.html

4

3 回答 3

0

您可以使用:contains()jQuery 选择器,然后基于此隐藏信息。

  $("div").not(":contains('marc')").hide();

快速演示

于 2013-01-08T10:34:40.783 回答
0

如果你想做这个客户端,那么试试 JQuery。您可以使用该$.each方法迭代每个元素并删除那些不包含“Marc”的元素

$(document).ready(function() {
    $('.schedule tr').each(function(index){
         if ($(this).html().indexOf('Marc') === -1)
             $(this).hide();
    });
});
于 2013-01-08T10:37:19.627 回答
0

选择:contains器是完美的选择。但是,在您的具体情况下,要使其发挥作用,还需要付出更多努力。在我的测试中,似乎是由于动态加载的外部脚本中的一些损坏的 URL,jQuery或者$undefined. jQuery解决方法是在表(和其他外部脚本)加载后重新加载API。

[更新]

我正在重新发布.html我认为它呈现正确结构的文件的全部内容(对我来说,它适用于 Chrome)。为了实现所需的字体颜色和 URL 格式,您仍然需要进行一些必要的修改,您可以通过jQuery's.css()函数来实现,如下所示。请注意:

  1. 我完全删除了<style>...</style>标签和
  2. 我在动态加载外部脚本之后调用's标记waitForFnc中的函数。<body><script>

对于需要水平滚动以查看完整jQuery样式格式,我深表歉意,但它与解决方案并不真正相关,直到您想修改它时应用您自己的格式。

<html>
    <head>

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
        <script>
            var count=0;

            function waitForFnc(){
                if(typeof $ != "undefined")
                {
                    if($("tr.bikram_yoga").length==0){
                       window.setTimeout(waitForFnc,50);
                    }
                    else
                    {
                            $(" div.healcode .header, div.healcode table.schedule tr th, div.healcode table.schedule tr.odd td, div.healcode table.schedule tr.even td").css("background-color","#f4f4f4");
                            $(".location, span.print_text, a.print_version, .mbo_class, span.day_links, .header, span.hc_date_year, div:nth-of-type(10), a[href*='100000210'], a[href*='/13/'], a[href*='100000242'], a[href*='100000201'], a[href*='/142/'], a[href*='100000174'], a[href*='100000229'], a[href*='100000053'],th.trainer").hide();
                            $("div.healcode").css("padding","20px 0 0 20px !important");
                            $("div.healcode span.hc_day").css({"margin-left": "0 !important",
            "text-align": "left !important"});
                            $("div.healcode table.schedule").css("border","none !important");
                            $("table .schedule, tr schedule_header th").css("background-color","#f4f4f4");
                            $("tr.bikram_yoga").not(":contains('Marc')").hide();
                    }
                }
                else{
                    if(count==0){
                        var oHead = document.getElementsByTagName('HEAD').item(0);
                        var oScript= document.createElement("script");
                        oScript.type = "text/javascript";
                        oScript.src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
                        oHead.appendChild( oScript);
                        count=count+1;
                    }
                    window.setTimeout(waitForFnc,50);
                }
            }
        </script>
    </head>
    <body>
        <table>
            <tr>
                <td align="left" valign="top">
                <div style="background-color: white;">
                <script type="text/javascript">
                    id = "ki1120mmvd";
                    name = "schedules";
                    document.write(unescape("%3Cscript src='http://healcode.com/javascripts/hc_widget.js' type='text/javascript'%3E%3C/script%3E"));
                    waitForFnc();
                </script>
                <noscript class="normal_left_yellow">
                    Please enable Javascript in order to view the class schedule: <a href="http://healcode.com" target="_blank">HealCode</a>
                </noscript>
                </div>
                </td>
            </tr>
        </table>
    </body>
</html>
于 2013-01-08T12:41:14.187 回答