我正在尝试创建一个简单的设置,以便当某个代码输入到表单框中时,会显示一个隐藏的元素。 如果你能帮助我,那就太好了。 谢谢!
<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/
I'm trying to create a simple set-up so that when a certain code is entered into a form box, then a hidden element shows. If you could help me out, that'd be great. Thanks!
<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/
最满意答案
您的代码中唯一的问题似乎是您的代码缺少一些字符。 以下是它的外观:
... 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/
It seems your only problem in your code is that your codes missing a bit of chars. Here's how it should look:
... if ($('#pwd').val() == "supportingcauses"){ $('#content').show('slow'); } ...I added the # to signify its an id and the parenthesis to signify supportingcauses is a string.
EDIT
The full correct code would be:
<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>Or as shown here: http://jsfiddle.net/nayish/MrjxY/3/
更多推荐
发布评论