2014-03-01 22 views
1
<script type="text/javascript"> 
var button = document.getElementById("button"); 
var idTab5 = document.getElementById("idTab5"); 
var button2 = document.getElementById("button2"); 

function showwMore() { 
    button.style.display="none"; 
    idTab5.style="overflow:hidden;display:block;height:100%;font-size:12px;line-height:14px;"; 
     button2.style.display="block"; 

} 

function showwLess() { 
    button2.style.display="none"; 
    idTab5.style="overflow:hidden;height:250px;font-size:12px;line-height:14px;"; 
    button.style.display="block"; 
} 
</script> 

,这是其他代码:的Javascript:上按钮改变股利大小单击

{if $product->description|count_characters:true > 350 } 
     {* full description *} 
     <div id="idTab5" style="overflow:hidden;height:250px;font-size:12px;line-height:14px;">{$product->description}</div> 
     <input id="button" type="button" style="margin-top:5px;font-size:12px;color:white; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar +" onclick="showwMore()"> 
     <input id="button2" type="button" style="margin-top:5px;display:none;font-size:12px;color:white; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar -" onclick="showwLess()"> 
    {else} 
     <div id="idTab5" style="overflow:hidden;height:250px;font-size:12px;line-height:14px;">{$product->description}</div> 
    {/if} 

现在它似乎没什么问题,但的onclick,股利心不是越来越大,任何想法,为什么会出现这种情况?香港专业教育学院多次检查代码无法找出为什么它不工作,我错过了什么?

回答

0

对于使用多个样式由JavaScript可以使用setAttribute()

应该

idTab5.setAttribute("style", "overflow:hidden;display:block;height:100%;font-size:12px;line-height:14px;"); 

或者

可以使用cssText属性元素

上使用CSS作为字符串
idTab5.style.cssText = "overflow:hidden;display:block;height:100%;font-size:40px;line-height:14px;"; 
代替

idTab5.style="overflow:hidden;display:block;height:100%;font-size:12px;line-height:14px;"; 
+0

你一定是在跟我开玩笑,在开始我的代码正在工作,突然它停止工作..现在改变刚才你建议再工作...... jeez,非常感谢。 – user1738483

+0

你有什么想法如何实现一个小小的CSS动画,因此该div不会变得更快? – user1738483

+0

它http://stackoverflow.com/questions/15768242/trying-to-use-basic-javascript-to-animate-a-div-and-make-it-bigger-but-have-it-g给出了一些上下文给你。 –

0

HTML:

<div id="idTab5" style="height:250px;font-size:12px;line-height:14px; border:1px solid black;"></div> 
     <input id="button" type="button" style="margin-top:5px;font-size:12px;color:black; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar +" onclick="showwMore()"> 
     <input id="button2" type="button" style="display:none;margin-top:5px;display:block;font-size:12px;color:white; width:120px;background:#4e3248;border:none;height:30px;border-radius:5px;" value="Mostrar -" onclick="showwLess()"> 

JAVASCRIPT:

var button = document.getElementById("button"); 
var idTab5 = document.getElementById("idTab5"); 
var button2 = document.getElementById("button2"); 

function showwMore() { 
    button.style.display="none"; 
    idTab5.style="display:block;height:100%;font-size:12px;line-height:14px; border:1px solid black;"; 
     button2.style.display="block"; 

} 

function showwLess() { 
    button2.style.display="none"; 
    idTab5.style="height:250px;font-size:12px;line-height:14px; border:1px solid black;"; 
    button.style.display="block"; 
} 

看到FIDDLE

+0

这不起作用,你不能像你那样使用多种风格。 'idTab5.style =“高度:250像素;字体大小:12px的;' –