我有以下使用jQuery的Javascript代码:
$(document).ready(function () {
$('#answer').hide(); //hiding the element
$('#questionOne').click(function () {
$('#answer').show();但是,该元素在加载时不会被隐藏。我的HTML是这样的:
<p id="answer">All requests of this nature are required to be submitted via our website www.mufoundation.org/charityrequests. Due to the volume of requests we receive, we require at least 6 weeks notice prior to your event. If your event does not fall within this timescale unfortunately, we will not be able to help.</p>我似乎无法隐藏段落答案元素。我该怎么做呢?
发布于 2014-06-08 03:38:29
如果您总是在加载时隐藏它,那么在加载时不隐藏它,而是附加一个将其设置为隐藏的CSS类,这不是更好的做法吗?要做到这一点非常简单,只需修改代码即可。
创建一个名为hide的CSS类
.hide{
display : none;
}添加下面的类。
<p id="answer" class="hide">All requests of this nature are required to be submitted via our website www.mufoundation.org/charityrequests. Due to the volume of requests we receive, we require at least 6 weeks notice prior to your event. If your event does not fall within this timescale unfortunately, we will not be able to help.</p>发布于 2014-06-08 03:40:27
如果这就是您拥有的所有jQuery,那么您可能忘记了在脚本末尾添加}); });。所以你的代码应该是这样的;
$(document).ready(function () {
$('#answer').hide();
$('#questionOne').click(function () {
$('#answer').show();
});
});如果这还不能解决您的问题,那么您确定包含了适当的jQuery库吗?
发布于 2014-06-08 03:41:17
如果你发布了正确的代码,那么它就是错误的语法。
正确的代码
$(document).ready(function () {
$('#answer').hide(); //hiding the element
$('#questionOne').click(function () {
$('#answer').show();
}); });<-- you forgot the clossing brackets我希望是这样的!如果它起作用了,请告诉我。
https://stackoverflow.com/questions/24100850
复制相似问题