简体   繁体   English

在文本区域中搜索指定的文本-jQuery / Javascript

[英]Search specified text in text area - jQuery/Javascript

I have a text area with HTML content,now i want to search there for specified text,if text area contains the text i need to return TRUE or FALSE. 我有一个包含HTML内容的文本区域,现在我要在此处搜索指定的文本,如果文本区域包含需要返回TRUE或FALSE的文本。

also is there any way to check that a specified DOM is on that TEXT AREA [WITH HTML CONTENT] ? 还有什么方法可以检查指定的DOM是否在该TEXT AREA上[具有HTML内容]?

Ex : 例如:

<html>
<head>
</head>
<body background="" bgcolor="red">
</body>
</html>

So now i want to check that the BODY tag have Background or bgcolor,if it contains i need to return true,how can i do this ? 所以现在我要检查BODY标签是否有Background或bgcolor,如果包含我需要返回true,我该怎么做? Actually i am trying to build a UI for editing HTML,if the html area contain 其实我正在尝试建立一个用于编辑HTML的UI,如果html区域包含

Thank you. 谢谢。

var text = $('#textarea').val();
var regex = /.../;
var found = text.match(regex);
if (found != null){return 1}

You can use indexOf , see the following example here: http://jsfiddle.net/mikhailov/S5jaz/2/ 您可以使用indexOf ,请参见此处的以下示例: http : //jsfiddle.net/mikhailov/S5jaz/2/

html HTML

<textarea id="txt">
  Here I am
</textarea>

JS JS

var txt = $('#txt').val();
var word1 = txt.indexOf('Heref') != -1;    // false
var word2 = txt.indexOf('Here I') != -1;   // true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM