jsfiddle 中的 html 代码正在生成,所以我们必须添加两个 .hide 或两个 .show。所以我将它们包装在一个 div 中。像这样
<span class="createMessage">
<span>Create Message</span>
</span>
<div id="messagePop" class="messagePopper">
<div id="light" class="white_content">
<div class="topborder"><span>NewMessage</span></div>
<div class="formbody">
<form id="privatemessage" action="/privmsg" method="post" name="post" class="newmessage">
<input placeholder="Message To:" name="username[]" onfocus="if(this.value == 'Message To:'){this.value = '';}" type="text" onblur="if(this.value == ''){this.value='Message To:';}" class="usernameinput">
<input required placeholder="Subject:" onkeypress="if (event.keyCode==13){return false}" maxlength="64" name="subject" onfocus="if(this.value == 'Subject:'){this.value = '';}" onblur="if(this.value == ''){this.value='Subject:';}" type="text" class="usernameinput"/>
<textarea class="noThis" name="message" onfocus="if(this.value == 'Type your message here'){this.value = '';}" onblur="if(this.value == ''){this.value='Type your message here';}" >Type your message here</textarea>
</div>
<div id="bottombuttons">
<span class="button"><input type="submit" value="Submit" name="post" class="submitbutton uiButton uiButtonConfirm uiButtonLarge">
</form>
<button class="submitbutton cancelButton uiButton uiButtonConfirm uiButtonLarge">Cancel</button></span>
</div>
</div>
<div id="fade" class="black_overlay"></div>
</div>
像这样的jQuery:
$(document).ready(function() {
$("#messagePop").hide();
$('.createMessage').click(function() {
$('#messagePop').show();
});
$('#fade').click(function() {
$('#messagePop').hide();
});
$('.cancelButton').click(function() {
$('#messagePop').hide();
});
});
在大家的帮助下,我意识到我是一个多么愚蠢的人,我正在纠正自己。并想向大家展示。
http://jsfiddle.net/6aNL5/3/