3

我试试这个:

form['comment'] = '<blockquote>test</blockquote><a href="#">test</a> <Your reply here>';

if($(form['comment']).search('<Your reply here>'))
    alert(1)
else
    alert(0)

但是有这个错误:

TypeError: $(form.comment).search 不是函数

我解决了这个问题:

if(form['comment'].value.search('<Вашият отговор тук>') != -1)
    alert(1)
else
    alert(0)
4

2 回答 2

3

你想要的是$(form['comment']).text().search()

所以:

form = [];
form['comment'] = '<blockquote>test</blockquote><a href="#">test</a> <Your reply here>';

if(form['comment'].search('<Your reply here>') != -1)
    alert(1)
else
    alert(0)​

这是一个工作示例

于 2012-09-16T14:23:32.077 回答
0

要找出与其他字符串匹配的字符串,您不需要 jQuery!。

var comment = "<blockquote>test</blockquote><a href="#">test</a> <Your reply here>",
    search = "<Your reply here>";


comment.indexOf( search ) != -1;  //  indexOf returns -1 when search does not match
/<Your reply here>/.test( comment ); // returns true when search is in comment. 
于 2012-09-16T19:47:42.647 回答