English 中文(简体)
定 义 在条件成熟之前
原标题:Make setTimeout Call Itself, Until Condition is True

I have an input-field inside a form, which class changes dynamically, depending on an ajax-script (which i can not modify) from "foo" to "foo bar" back to "foo". I would like to modify the style of the field, when it s length is > 0, it s value does not contain "nid" and it s class is not "bar". My first idea was to have a setTimeout, that gets called every time the input field s class is "bar", until it is "foo". But i do not know whether this is good practice, nor how to do it …

问题回答

The easiest thing would be to bind the change or keydown event on the element to catch if the contents of the field matches.

如果与你相匹配,如果与你相匹配,则添加一个类别 fxbaz

这将使你能够把这个要素带上安全局。 采用<条码>条码/代码”的规则,该规则将高于<条码>baz<>。

投入活动<代码><>field>/code>

罚款。 或者,如果满足条件,你可以使用将多次发射的隔膜,然后打上清晰的间隔。

http://whattheheadsaid.com 该系统使所有主要浏览器的超文本5<代码>输入活动实现正常化,从而可以发现关键板的投入、拼凑的更正、过去、ging积和安放等。

借助这一gin,你的法典可能会研究这样的问题:

$("#myInput").input(function () {
    var $this = $(this), val = this.value;
    if (val.length && val.indexOf("nid") === -1 && !$this.hasClass("bar"))
        $this.css("color", "red");
    else
        $this.css("color", "green");
});

http://jsfiddle.net/hVDP8/。

oninput has many benefits over using timers or the onkeyup event, such as code execution before the new value is painted on the screen. In fact, it s perfect for this type of situation.





相关问题
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.

热门标签