English 中文(简体)
如何强调与格雷克相匹配的部分
原标题:How to highlight the portion matched with regex

我试图强调(有红色)投入的错误部分(用户可以轻易发现错误之处和错误是什么),并将错误部分与格雷克相匹配。

我尝试了如下内容(例如,我接受信件,但不是数字)。

$("#myInputId")
    .filter(function() {
        return this.value.match(/[d]/);
    })
    .addClass("error")

但是,上述法典强调了整个投入,而不仅仅是错误部分。

我只想让我所说的话更加清楚:

“entergraph

www.un.org/Depts/DGACM/index_spanish.htm 我在试图做到这一点时,没有增加任何强调案文的 j。

问题回答

过滤功能的回报是正确的,因为this.中的内容与规定的格列维。 因此,整个要素<代码>#myInputId为之。 对于这个要素,你适用<代码>error。

你们只需要将这一类别适用于相关部分。 您或许应该做些什么,取而代之的是 >in。 缩略语

这是:

<div id="myInputId">James1234</div>

为此:

<div id="myInputId">James<span class="error">1234</span></div>

你们可以通过使用发现的扼杀手段来实现这一目标。

var newStr = wholeStr.replace(foundStr,  <span class="error"> +foundStr+ </span> );

我认为,这是因为你将“error”这一类内容添加到其中所有文本的“James1234”。

此时,我认为情况正好如此。

<p class="error">
    james1234
</p>

if it was free text and you did text replace and changed the html to something like this

<p>
    james<span class="error"/>1234<span/>
</p>

为此,我认为你需要做这样的事情。

    var searchterm =  1234 
    value.replace(searchTerm, "<span class= error />" + searchterm + "<span/>");




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签