我尝试了一种我在某处读到的技术,但它不起作用。该技术是创建一个名为 hidden
的类,该类在函数调用时被删除。由于我是 JQuery 的新手,我认为我编写 onclick 函数的方式可能有问题。我会发布我的尝试,如果您能帮助我纠正我的错误,我将不胜感激。
HTML:
<button onclick="function() {$('newthreaddiv').removeClass('hidden');}">New Thread</button>
<div class="boardbox hidden" id="newthreaddiv">
<p>Username:<input class="threadipt" type="text"</p>
<p>Password:<input class="threadipt" type="text"></p>
<p>Title:<input class="threadipt" type="text"></p>
<p>Content:</p>
<button class="threadbutton">bold</button>
<button class="threadbutton">italicize</button>
<button class="threadbutton">underline</button>
<button class="threadbutton">insert image</button>
<textarea id="newthreadtxt"></textarea>
<p><button onlick="phpfunction">Create Thread</button></p>
</div>
CSS:
div.boardbox
{
background-color: #ccc;
padding: 5px;
margin: 20px;
}
div.hidden
{
display: none;
}
最佳答案
function() {$('newthreaddiv')
应该是 function() {$('#newthreaddiv')
你错过了 #
.
此外,我不确定这是否只是一个拼写错误或在您的实际代码中,但您的用户名输入字段中缺少右括号 (>
)。
关于javascript - 在页面加载时隐藏一个div,然后在单击按钮时取消隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23121828/