在变量中查找字符串部分

时间:2013-06-05 13:13:23

标签: javascript jquery html string

继续这个问题:

Select first complete string matching partial string

我将外部网站html存储在变量中。我想在第四个副本中搜索该变量,这是不够的?'然后选择“是”'或者'否'直接坐在它之后。外部HTML的片段是:

    <section class="top media" style="display:block;">
    <a href="http://wasitenough.com/image/52215562284"><img src="http://24.media.tumblr.com/438cd1f5e94c87e32dd14bbe869469b1/tumblr_mnx64jj7kf1spmjuzo1_1280.jpg" alt="Venue: Crussh
    Dish: Chicken teriyaki noodle soup

    Was it enough? No&nbsp;"> </a>
   </section>

我当前的代码返回每个实例。

$(content).find('*:contains("Was it enough")').each(function(index, crntNode){

        var parts = $(crntNode).text().split('?');
        var flag = parts[1].trim();

        console.log('The flag was ' + flag);

        if(flag == 'Yes') {
            console.log('It was enough');
            $('#yesNo').text('It was enough');
        } else if (flag == 'No') {
            console.log('It was not enough');
            $('#yesNo').text('It was not enough');
        } else if (flag != 'No' && flag != 'Yes') {
            console.log('We are not sure if it was enough');
            $('#yesNo').text('We are not sure if it was enough');
        }
    });

0 个答案:

没有答案