0

初心者です。

現在WEBページの改修作業を行っています
あるリンク先からGETして別のページにタイトルやリンクを張りたいのですが、
タイトルの中身にある文字列が存在する場合、それを取得しない(記載しない)という
if条件分岐の書き方がわかりません

ご教示お願いします

$.ajax(
    {
        type: 'GET',
        dataType: 'xml',
        url: 'https://',
        timeout: 10000,
        success: function(data) {
            if($('item', data).length <= 0) {
                return false;
            } else {
                $(data).find('item').each(function(i) {
                    var item = {
                            title: $(this).find('title').text(),
                            link: $(this).find('link').text(),
                            pubDate: formatDate($(this).find('pubDate').text()),
                            img: $(this).find('img').text(),
                            thumbnail: 'news/images/img_cover.jpg',
                            class: 'cover',
                            playing: ''
                        };

                    if(item.img !== '') {
                        item.thumbnail = item.link.slice(0, item.link.lastIndexOf('/')) + '/' + item.img;
                        item.thumbnail = item.thumbnail.replace(/http:/g, 'https:');
                        item.playing = '<img src="news/images/icon_btn_start.png" alt="再生" class="btn_start">';
                        item.class='nocover'
                    }

                    switch (i) {
                        case 0:
                            break;
                        case 1:
                            break;
                        case 2:
                            break;
                        case 3:
                            break;
                        default:
                            return false;
                            break;
                    }

                    html = html
                            + tag.start
                            + '<a target="_blank" href="' + item.link + '">'
                            + '<figure>'
                            + '<div class="imgBox">'
                            + '<img src="' + item.thumbnail + '" alt="' + item.title + '" class="' + item.class + '">'
                            + item.playing
                            + '<div class="' + item.class + '"></div>'
                            + '</div>'
                            + '<figcaption>'
                            + '<p>' + item.title + '</p>'
                            + '<span>' + item.pubDate + '</span>'
                            + '</figcaption>'
                            + '</figure>'
                            + '</a>'
                            + tag.end;

                });
                $('#g-news-ticker').html(html);

            }
        },
        error: function(e) {}
    }
)
4
  • 「特定の文字列がタイトルに含まれていた場合」、でしょうか。
    – cubick
    2019年9月11日 3:02
  • if($('item', data).length <= 0)と同様にすればよいかと思いますが違いますでしょうか?(data内のTITLEタグの文字列を取得して判断してfalseで返す。)
    – wakuwaku
    2019年9月11日 4:06
  • 特定の文字列がタイトルに含まれていた場合です
    – shooo
    2019年9月12日 7:45
  • if($('title', data).length == 特定の文字列)と記載すればよいのでしょうか
    – shooo
    2019年9月12日 7:47

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。