2011-08-23 84 views
1

我想创建一个简单的设置,以便当某个代码输入到表单框中时,然后显示一个隐藏的元素。如果你能帮助我,那会很棒。谢谢!密码来显示内容

<form> 
    Enter the passcode to see the content: 
    <input id="pwd" type="text" name="pwd" /> 
</form> 
<div id="content" style="display:none;"> 
    testing 123 
</div> 
<script> 
    $function(){ 
     $(form).keyup(function() { 
      $('input').trigger('change'); 
     }); 
     if ($('pwd').val() == supportingcauses){ 
      $('content').show('slow'); 
     } 
    }; 
</script> 

http://jsfiddle.net/jaruesink/RTG4f/

+0

这里有什么问题? – helloandre

+2

这不是最好的主意,因为任何人以HTML格式查看您的HTML页面将能够看到您的隐藏内容......所以没有真正的理由来保护它的密码... – Nayish

+1

它看起来nayish建议服务器之旅,你可以用AJAX做。 – mozillanerd

回答

0

看来你的代码中的唯一的问题是,你的代码缺少一些字符。下面是它应该是什么样子:

... 
if ($('#pwd').val() == "supportingcauses"){ 
    $('#content').show('slow'); 
} 
... 

我加入了#以表示它的ID,并表示supportingcauses是一个字符串的括号。

编辑

完整正确的代码是:

<form> 
    Enter the passcode to see the content: 
    <input id="pwd" type="text" name="pwd" /> 
</form> 
<div id="content" style="display:none;"> 
    testing 123 
</div> 
<script> 
    $("#pwd").keyup(function() { 
     if ($('#pwd').val() == "supportingcauses"){ 
      $('#content').show('slow'); 
     } 
    }); 
</script> 

或者如下所示:http://jsfiddle.net/nayish/MrjxY/3/