【发布时间】:2011-07-04 11:56:30
【问题描述】:
我的简单 jQuery 脚本在 IE 中不起作用。
请帮忙。
完整的 HTML 代码在这里:
<script type="text/javascript" src="jquery-1.4.2.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
var cvalue = $(".space").css("backgroundColor");
$(".space").css("color",cvalue);
});
</script>
<style>
table.tdata td {
padding: 10px;
}
tr.zrow1 {
background-color: #ccc
}
tr.zrow2 {
background-color: #aaa
}
tr.zrow1 td, tr.zrow2 td {
border-top: 1px solid white;
border-left: 1px solid #ccc;
}
table.tdata tr.thead1 {
text-align: center;
}
table.tdata tr.thead {
background-color: #003;
color: white;
text-align: center;
}
.thrColFixHdr #header h1 {
margin: 0;
padding: 10px 0;
}
.thrColFixHdr #mainContent {
margin: 0 200px;
padding: 0 10px;
}
</style>
<div id="areaRec">
<h2 style="margin-top: 0pt;">Sample text</h2>
<p>Sample text Sample text Sample text Sample text Sample text Sample text Sample text Sample text<span class="space">_</span>text Sample text Sample text Sample text Sample text<br />text Sample text Sample text Sample text Sample text text Sample text Sample text Sample text Sample text text Sample text Sample text Sample text Sample text text Sample text Sample text Sample text Sample text text Sample text Sample text Sample text Sample text</p>
<h3 style="margin-top: 0pt;">text Sample text Sample text </h3>
<p>Sample textSample textSample textSample textSample textSample text<span class="space">_</span>Sample textSample textSample textSample textSample text<span class="space">_</span>Sample textSample textSample text textSample textSample textSample textSample textSample textSample textSample textSample textSample textSample textSample textSample textSample textSample text.</p>
<h3 style="margin-top: 0pt;">Sample textSample textSample textSample text</h3>
<div class="show_job">
<table class="job-position" border="0" cellspacing="1" cellpadding="4">
<tbody>
<tr class="zrow2">
<td class="title-col" width="181" valign="top">Sample text</td>
<td width="457" valign="top">
<ul>
<li>text Sample text Sample text Sample text Sample text<span class="space">_</span>Sample text</li>
<li>text Sample text Sample text Sample text Sample text<span class="space">_</span>Sample text</li>
<li>text Sample text Sample text Sample text Sample text<span class="space">_</span>Sample text Sample text<span class="space">_</span>Sample text:</li>
</ul>
<blockquote><ol>
<li>Adobe Photoshop</li>
<li>Adobe InDesign</li>
<li>Adobe Illustrator</li>
</ol><ol> </ol></blockquote>
<blockquote><ol> </ol></blockquote>
</td>
</tr>
<tr class="zrow1">
<td class="title-col" width="181" valign="top">Sample text</td>
<td width="457" valign="top">Sample text</td>
</tr>
<tr class="zrow2">
<td class="title-col" width="181" valign="top">Sample text</td>
<td width="457" valign="top">Sample text</td>
</tr>
<tr class="zrow1">
<td class="title-col" width="181" valign="top">Sample text</td>
<td width="457" valign="top">Sample text</td>
</tr>
<tr class="zrow2">
<td class="title-col" width="181" valign="top">Sample text </td>
<td width="457" valign="top">Sample text</td>
</tr>
<tr class="zrow1">
<td class="title-col" width="181" valign="top">Sample text </td>
<td width="457" valign="top">Sample text<span class="space">_</span>Sample textSample textSample textSample text<span class="space">_</span>Sample textSample textSample textSample textSample text </td>
</tr>
</tbody>
</table>
</div>
</div>
我认为 IE 不理解 css 中的透明值,有什么解决办法吗?
最终解决方案:
$('.space').each(function(index, value){
var cvalue = $(".space").css("backgroundColor");
if(cvalue == '' || cvalue == 'transparent'){
var pcolor = ($(this).closest('div, p, tr').css('backgroundColor'));
if (pcolor == '' || pcolor == 'transparent'){
//this means the closet tag hasnt any bgcolor and it is white
$(this).css('color','white');
}else {
$(this).css('color',pcolor);
}
}else{
$(this).css('color',cvalue);
}
});
【问题讨论】:
-
你能不能也给我们看看你的相关html?我的意思是关于 .space
-
那为什么在ff、safari、opera和chrome等所有标准浏览器中都可以?
标签: jquery internet-explorer coding-style