javascript text trigger
i have a page that is reading events from a data base, the thing that i wanna do is when a specif开发者_运维技巧ic "XYZ" text appears in the text box automatically the page open a popup, or make an alert event.
thanks for your help. :)
At a high level, you want to attach to the keyup event on your text box, and query it's value. If the value matches your criteria, you then show the alert.
If you're using jQuery, like so:
$('#myTextBox').keyup(function()
{
if($(this).val() == 'xyz')
alert('Condition Triggered!');
});
$('#textBox').keyup(function() {
//search the text box's value for the string you want.
//start the search from the end of the value
var val = $(this).val();
if ( val.indexOf( myString, val.length - myString.length ) > -1 ) {
alert('Clear');
}
}
http://www.w3schools.com/jsref/jsref_indexof.asp
精彩评论