例如:有如下HTML片段 <div id="mydiv" style="overflow:hidden;position:relative;left:0;top:0;z-index:8998;width:100%;height:100%;">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="z-index:8998;overflow:hidden;">
<tr>
<td align="center" valign="middle" nowrap="nowrap" width="100%" style="text-overflow:clip;overflow:hidden;font-family:宋体;font-size:9pt;font-weight:normal;font-style:normal;text-decoration:none;line
-height:100%">设置</td>
</tr>
</table>
</div>想利用JS动态修改“设置”按钮的"line-height属性,该如何实现?
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="z-index:8998;overflow:hidden;">
<tr>
<td align="center" valign="middle" nowrap="nowrap" width="100%" style="text-overflow:clip;overflow:hidden;font-family:宋体;font-size:9pt;font-weight:normal;font-style:normal;text-decoration:none;line
-height:100%">设置</td>
</tr>
</table>
</div>想利用JS动态修改“设置”按钮的"line-height属性,该如何实现?
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="z-index:8998;overflow:hidden;">
<tr>
<td id="wc" align="center" valign="middle" nowrap="nowrap" width="100%" style="text-overflow:clip;overflow:hidden;font-family:宋体;font-size:9pt;font-weight:normal;font-style:normal;text-decoration:none;line
-height:100%">设置</td>
</tr>
</table>
</div><script type="text/javascript">
window.onload = function () {
var wc = document.getElementById("wc");
wc.style.lineHeight = "30px";
};
</script>
不过看不出效果,因为你设置了line-heigth也梅效果。
obj.style.lineHeight = [];
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" style="z-index:8998;overflow:hidden;">
<tr>
<td align="center" valign="middle" nowrap="nowrap" width="100%" style="text-overflow:clip;overflow:hidden;font-family:宋体;font-size:9pt;font-weight:normal;font-style:normal;text-decoration:none;line
-height:100%">设置</td>
</tr>
</table>
</div><script type="text/javascript">
window.onload = function () {
var wc = document.getElementById("mydiv").getElementsByTagName("td")[0];
wc.style.lineHeight = "30px";
};
</script>
昂,一样的道理。。
{
var allButtons = document.getElementsByTagName("button");
var itag = 0;
for (var i=0; i<allButtons.length; i++)
{
oButton = allButtons[i];
if(oButton.pbtype="button")
{
var wc = document.getElementById(oButton.id + "_div").getElementsByTagName("td")[0];
wc.style.lineHeight="150%";
}
}
}但发现有些页面的document.getElementById(oButton.id + "_div")提示“为空或不是对象”进一步考察研究中...........
那个是不是因为oButton.id = 空导致的?
<button pbtype="button" id="xxxx" ....>
<div id="yyyyy" .....>
<table 无ID 无name .....>
<tr>
<td ....>按钮文字</td>
</tr>
</table>
</div>
</button>
你这里写错了。。
if(oButton.pbtype="button")改成if(oButton.pbtype=="button")
并且正规的话应该改成if(oButton.getAttribute("pbtype") =="button")
function My_AlterButton ( )
{
var allButtons = document.getElementsByTagName("button");
for (var i=0; i<allButtons.length; i++)
{
oButton = allButtons[i];
if(oButton.pbtype="button")
{
oDiv = document.getElementById(oButton.id + "_div");
if(oDiv) {
var wc = document.getElementById(oButton.id + "_div").getElementsByTagName("td")[0];
wc.style.lineHeight="150%";
}
}
}
}
function My_AlterButton ( )
{
var allButtons = document.getElementsByTagName("button");
for (var i=0; i<allButtons.length; i++)
{
oButton = allButtons[i];
if(oButton.getAttribute("pbtype")=="button")
{
oDiv = document.getElementById(oButton.id + "_div");
if(oDiv) {
var wc = document.getElementById(oButton.id + "_div").getElementsByTagName("td")[0];
wc.style.lineHeight="150%";
}
}
}
}应该算圆满了!谢谢!