开发者

Use jQuery to show/hide input based on another input's value

开发者 https://www.devze.com 2023-02-07 19:37 出处:网络
I want to hide a specific input on a page unless a user types a Hotmail address into a different input. Whenever the user types in a hotmail address, I want to show the input. If the address is remove

I want to hide a specific input on a page unless a user types a Hotmail address into a different input. Whenever the user types in a hotmail address, I want to show the input. If the address is removed, I'd like it to d开发者_如何学Pythonisappear. How can this be accomplished with jQuery?

I know I'm going about this incorrectly, but here's what I have so far:

$(function() {

 if($("select#combobox").val() *= '@hotmail') {

   $('#hotm').show();

 }

 else {

   $('#hotm').hide();

 }

 });


You can try something like this:

$("select#combobox").blur(function() {
  if ($(this).val().indexOf('@hotmail')>-1) 
    $('#hotm').show();
  else
    $('#hotm').hide();
});

this is to check after the user takes focus off the combobox...you might wanna use a different event depending on your needs/style, like .change() or whatever.


This checks direct on typing... Here is a working example: http://jsfiddle.net/Ltapp/

var myString = '@hotmail';
$("input").keyup(function () {
var value = $(this).val();
    if($(this).val().match(myString)) {
        $('#hotm').show();
    } else {
        $('#hotm').hide(); 
    }
});
0

精彩评论

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