开发者

Javascript: OnChange not firing

开发者 https://www.devze.com 2023-02-13 01:36 出处:网络
I have a textbox that sets the onchange property but when i start typing in the textbox the onchange doesnt fire initially. it never fires whats going on?

I have a textbox that sets the onchange property but when i start typing in the textbox the onchange doesnt fire initially. it never fires whats going on?

Here is the code:

VB.NET

      Dim textBoxUrlYoutube As New TextBox
      divUrlTextBoxContainer.Controls.Add(textBoxUrlYoutube)
      textBoxUrlYoutube.CssClass = "textboxyoutubeurlmediaselecto开发者_C百科r"
      textBoxUrlYoutube.Attributes.Add("onchange", 
                                       "YoutubeUrlSaveTextBoxOnChange(this)")

JAVASCRIPT

function YoutubeUrlSaveTextBoxOnChange(el) {

    var text = $(el).val();

    if (text == '') {

        $("a.linkplayyoutubeurl2").attr("class", "linkplayyoutubeurl1");
        $("div.divlinktext2").attr("class", "divlinktext1");

    }
    else {

        $("a.linkplayyoutubeurl1").attr("class", "linkplayyoutubeurl2");
        $("div.divlinktext1").attr("class", "divlinktext2");
    }

}


Change events fire when the focus is lost, if a change has occurred.

If you want a change to fire with every keypress, use the keypress event.

0

精彩评论

暂无评论...
验证码 换一张
取 消