开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜