Javascript: OnChange not firing
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.
精彩评论