如何使用jquery在页面上显示特定的div id?
我想在页面上显示具有特定 id 的特定 div。我能够显示带有类信息的 div,但是当我尝试通过提供 div id 来访问它时,它不起作用,这就是我尝试从 javascript 访问它的方式。
if((document.getElementById("apMain.stageId").value) == "11"){
doShow();
}else{
alert('else');
}
function doShow(){
$(".bill_info").show();
}
我想使用 id= stg_Pdel 访问 div
,我已尝试使用
function doShow(){
$('#stg_Pdel').show();
}
但无法在页面上打开该 div,正确的做法应该是什么?
我的div是:
<div class="bill_info">
<h3>Additional required fields</h3>
<div id="stg_install">
<div class="row">
<span class="label">
<form:label path="billingInfo.otc" cssClass="normalText" cssErrorClass="normalTextRed" >OTC:</form:label>
</span>
<span class="formw">
<form:input path="billingInfo.otc" cssClass="normalField" cssErrorClass="validationError" size="25" disabled='true'/>
</span>
<span class="error">Values for all charge fields must be numeric.</span>
</div>
</div>
<div id="stg_Pdel">
<div class="row">
<span class="label">
<form:label path="billingInfo.priceId" cssClass="normalText" cssErrorClass="normalTextRed" >Price Type:</form:label>
</span>
<span class="formw">
<form:select path="billingInfo.priceId" cssErrorClass="validationError" disabled='true'>
<form:options items="${priceTypes}" itemValue="key" itemLabel="value" />
</form:select>
</span>
</div>
</div>
<div id='stg_closed'>
<div class="row">
<span class="label">
<form:label path="billingInfo.billingClassId" cssClass="normalText" cssErrorClass="normalTextRed" >Billing:</form:label>
</span>
<span class="formw">
<form:select path="billingInfo.billingClassId" cssErrorClass="validationError" disabled='true'>
<form:option value="" label="--Select--" />
<form:options items="${billingTypes}" itemValue="key" itemLabel="value" />
</form:select>
</span>
</div>
</div>
<div style="clear:both"></div><br/>
</div>
I want to show a particular div with particular id on the page. I am able to show the div with class information but when I try to access it by giving div id then it is not working, this is how am trying to access it from javascript.
if((document.getElementById("apMain.stageId").value) == "11"){
doShow();
}else{
alert('else');
}
function doShow(){
$(".bill_info").show();
}
I want to access div with id= stg_Pdel
, I have tried using
function doShow(){
$('#stg_Pdel').show();
}
but am not able to get the div open on the page, what should be the right approach of doing it ?
My div is:
<div class="bill_info">
<h3>Additional required fields</h3>
<div id="stg_install">
<div class="row">
<span class="label">
<form:label path="billingInfo.otc" cssClass="normalText" cssErrorClass="normalTextRed" >OTC:</form:label>
</span>
<span class="formw">
<form:input path="billingInfo.otc" cssClass="normalField" cssErrorClass="validationError" size="25" disabled='true'/>
</span>
<span class="error">Values for all charge fields must be numeric.</span>
</div>
</div>
<div id="stg_Pdel">
<div class="row">
<span class="label">
<form:label path="billingInfo.priceId" cssClass="normalText" cssErrorClass="normalTextRed" >Price Type:</form:label>
</span>
<span class="formw">
<form:select path="billingInfo.priceId" cssErrorClass="validationError" disabled='true'>
<form:options items="${priceTypes}" itemValue="key" itemLabel="value" />
</form:select>
</span>
</div>
</div>
<div id='stg_closed'>
<div class="row">
<span class="label">
<form:label path="billingInfo.billingClassId" cssClass="normalText" cssErrorClass="normalTextRed" >Billing:</form:label>
</span>
<span class="formw">
<form:select path="billingInfo.billingClassId" cssErrorClass="validationError" disabled='true'>
<form:option value="" label="--Select--" />
<form:options items="${billingTypes}" itemValue="key" itemLabel="value" />
</form:select>
</span>
</div>
</div>
<div style="clear:both"></div><br/>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在该标签之前缺少结束
标签,因此它位于前一个标签(“stg_install”)内。外部“display: none”将覆盖(某种程度)内部
上的“display: block”(或其他内容)。
如果问题的最初帖子中没有出现
嵌套问题,那么您提到显示
时可能会提示问题。代码> 类“bill_info”。如果整个内容当前未显示,则在另一个
上调用
.show()
(“stg_Pdel”>) 将不会有任何影响。同样,无论“显示”样式设置为何,外部块都会隐藏它。
如果“.bill_info”
被隐藏,您需要执行以下操作:
您将传递“doShow”“stg_Pdel”、“stg_install”或“stg_angled”,并且它将确保显示这些内部
元素之一。 编辑更多详细信息 - 这个想法是执行以下操作:
元素并将其全部隐藏;
并使其可见
请注意,使用
.find()
并不是真正必要的,因为您正在按“id”值进行搜索,但它应该有效。如果您需要该功能在多个阶段上工作,您可以这样做:
You're missing a closing
</div>
tag right before that one, so it's inside the previous one ("stg_install"). An outer "display: none" will override (sort-of) the "display: block" (or whatever) on the inner<div>
.If it's not the
<div>
nesting issue that was present in the initial post of the question, then perhaps there's a hint of the problem where you mention showing the<div>
with class "bill_info". If that whole thing is currently not showing, then calling.show()
on another<div>
(the "stg_Pdel"<div>
) will have no effect. Again, the outer block will hide it no matter what it's "display" style is set to.If the ".bill_info"
<div>
is hidden, you need to do something like this:You'd pass "doShow" either "stg_Pdel", "stg_install", or "stg_closed", and it would make sure one of those inner
<div>
elements is showing. edit for more detail — The idea is to do the following things:<div>
elements and hide them all;<div>
and make it visibleNote that using
.find()
is not really necessary because you're searching by "id" value, but it should work.If you need the function to work on more than one stage, you could do it like this: