I want to have this div hide or show depending on what <%= ItemCount%>
is. If the number that comes up is less than five, I want the div to be hidden. If it is above 5, I want it to be visible. Any help would be gladly appreciated.
我希望根据<%= ItemCount%>是什么来隐藏或显示这个div。如果出现的数字小于5,我希望将div隐藏起来。如果它在5以上,我希望它是可见的。如有任何帮助,将不胜感激。
<div class="slideControl">
<a id="slidesPrev" onclick="return false" href="#">
<img src="/_assets/images/Arrowleft.png"
</a>
<%= ItemCount%> Total Products
<a id="slidesNext" onclick="return false" href="#">
<img src="/_assets/images/ArrowRight.png"
</a>
</div>
3 个解决方案
#1
0
Since this is probably an aspx page you can try to use it inside a javascript function.
因为这可能是一个aspx页面,您可以尝试在javascript函数中使用它。
if (<%= ItemCount %> < 5) {
$('.slideControl').hide();
}
And make sure that this javascript runs after page load.
确保这个javascript在页面加载之后运行。
#2
0
Try the following. No need to do jquery. There are also many other variations you can do.
试试下面的。不需要使用jquery。你还可以做很多其他的变化。
<div class="slideControl" style="<%= ItemCount < 5 ? "Display:None;" : ""%>">
#3
0
This is the code that ended up working.
这是结束工作的代码。
<script type="text/javascript">
$(document).ready(function(){
var itemCount = <%=ItemCount%>;
if (itemCount < 5) {
$("#productSlide").hide();
}
});
</script>
<div id="productSlide" class="slideControl">
<a id="slidesPrev" onclick="return false" href="#">
<img src="/_assets/images/Arrowleft.png" /></a>
<%= ItemCount%> Total Products
<a id="slidesNext" onclick="return false" href="#">
<img src="/_assets/images/ArrowRight.png" /></a>
</div>
#1
0
Since this is probably an aspx page you can try to use it inside a javascript function.
因为这可能是一个aspx页面,您可以尝试在javascript函数中使用它。
if (<%= ItemCount %> < 5) {
$('.slideControl').hide();
}
And make sure that this javascript runs after page load.
确保这个javascript在页面加载之后运行。
#2
0
Try the following. No need to do jquery. There are also many other variations you can do.
试试下面的。不需要使用jquery。你还可以做很多其他的变化。
<div class="slideControl" style="<%= ItemCount < 5 ? "Display:None;" : ""%>">
#3
0
This is the code that ended up working.
这是结束工作的代码。
<script type="text/javascript">
$(document).ready(function(){
var itemCount = <%=ItemCount%>;
if (itemCount < 5) {
$("#productSlide").hide();
}
});
</script>
<div id="productSlide" class="slideControl">
<a id="slidesPrev" onclick="return false" href="#">
<img src="/_assets/images/Arrowleft.png" /></a>
<%= ItemCount%> Total Products
<a id="slidesNext" onclick="return false" href="#">
<img src="/_assets/images/ArrowRight.png" /></a>
</div>