1

我想改变text color元素。我搜索了它,但没有得到正确的解决方案。当我使用它时,只需更改 td 的3 个边框颜色,但顶部边框仍然没有更改,我不知道为什么会这样。border color<TD>border-color:bluetd

而且我想改变text color使用tdjava脚本,但没有这样的属性。请建议我该怎么做?

我正在尝试创建日历控件这是我的代码...

 <script id="allTemplate" type="text/raj"> 
 <tr> 


          {{if "Su" == Sunday }}  
          <td>${Sunday}</td>
          {{else}}
            {{if date.getDate() == Sunday }}
             <td id="cell${Sunday}" style="border:1px solid blue;cursor: pointer" onclick="selectDate('${Sunday}','cell${Sunday}')">${Sunday}</td>
            {{else}}
                 {{if "" == Sunday }}
                  <td>${Sunday}</td>
                   {{else}}
            <td id="cell${Sunday}" style="cursor: pointer" onclick="selectDate('${Sunday}','cell${Sunday}')">${Sunday}</td>
                   {{/if}}
            {{/if}}
          {{/if}}
          {{if "Mo" == Monday }}  
          <td>${Monday}</td>
          {{else}}
            {{if date.getDate() == Monday }}
            <td id="cell${Monday}" style="border:1px solid blue; cursor: pointer" onclick="selectDate('${Monday}','cell${Monday}')"><font color="Red">${Monday}</font></td>
            {{else}}
                {{if "" == Monday }}
            <td>${Monday}</td>
               {{else}}
            <td id="cell${Monday}" style="cursor: pointer" onclick="selectDate('${Monday}','cell${Monday}')">${Monday}</td>
               {{/if}}
            {{/if}}
          {{/if}}
          {{if "Tu" == Tuesday }}  
          <td>${Tuesday}</td>
          {{else}}
            {{if date.getDate() == Tuesday }}
            <td id="cell${Tuesday}" style="border:1px solid blue; cursor: pointer" onclick="selectDate('${Tuesday}','cell${Tuesday}')"><font color="Red">${Tuesday}</font></td>
            {{else}}
                  {{if "" == Tuesday }}
            <td>${Tuesday}</td>
                   {{else}}
            <td id="cell${Tuesday}" style="cursor: pointer" onclick="selectDate('${Tuesday}','cell${Tuesday}')">${Tuesday}</td>
                   {{/if}}
            {{/if}}
          {{/if}}
          {{if "We" == Wednesday }}  
          <td>${Wednesday}</td>
          {{else}}
            {{if date.getDate() == Wednesday }}
            <td id="cell${Wednesday}" style="border:1px solid blue; cursor: pointer" onclick="selectDate('${Wednesday}','cell${Wednesday}')"><font color="Red">${Wednesday}</font></td>
            {{else}}
                 {{if "" == Wednesday }}
                 <td>${Wednesday}</td>
                 {{else}}
            <td id="cell${Wednesday}" style="cursor: pointer" onclick="selectDate('${Wednesday}','cell${Wednesday}')">${Wednesday}</td>
                 {{/if}}
            {{/if}}
          {{/if}}
          {{if "Th" == Thursday }}  
          <td>${Thursday}</td>
          {{else}}
            {{if date.getDate() == Thursday }}
            <td id="cell${Thursday}" style="border:1px solid blue; cursor: pointer" onclick="selectDate('${Thursday}','cell${Thursday}')"><font color="Red">${Thursday}</font></td>
            {{else}}
                 {{if "" == Thursday }}
                 <td>${Thursday}</td>
                 {{else}}
            <td id="cell${Thursday}" style="cursor: pointer" onclick="selectDate('${Thursday}','cell${Thursday}')">${Thursday}</td>
                 {{/if}}
            {{/if}}
          {{/if}}
          {{if "Fr" == Friday }}  
          <td>${Friday}</td>
          {{else}}
            {{if date.getDate() == Friday }}
            <td id="cell${Friday}" style="border:1px solid blue; cursor: pointer" onclick="selectDate('${Friday}','cell${Friday}')"><font color="Red">${Friday}</font></td>
            {{else}}
                {{if "" == Friday }}
                <td>${Friday}</td>
                {{else}}
            <td id="cell${Friday}" style="cursor: pointer" onclick="selectDate('${Friday}','cell${Friday}')">${Friday}</td>
                {{/if}}
            {{/if}}
          {{/if}}
          {{if "Sa" == Saturday }}  
          <td>${Saturday}</td>
          {{else}}
            {{if date.getDate() == Saturday }}
            <td id="cell${Saturday}" style="border:1px solid blue; cursor: pointer" onclick="selectDate('${Saturday}','cell${Saturday}')"><font color="Red">${Saturday}</font></td>
            {{else}}
                {{if "" == Saturday }}  
            <td>${Saturday}</td>
                {{else}}
            <td id="cell${Saturday}" style="cursor: pointer" onclick="selectDate('${Saturday}','cell${Saturday}')">${Saturday}</td>
                 {{/if}}
            {{/if}}
          {{/if}}


</tr> 

</script>

这是我想更改 td 的边框颜色的 j 查询模板,当条件为真时,它会更改 td 的边框颜色,但只有 3 个边缘而不是顶部一个。

4

3 回答 3

4

我想你正在寻找的是

var td = document.getElementById('something')
td.style.color="red"
td.style.border="1px solid blue"

您可以在这里看到它的实际效果。

于 2012-08-17T11:26:46.717 回答
0

如果您想纯粹在 CSS 中执行此操作,请注意您需要设置完整的边框样式td- 如果您只设置颜色,则只有那些不受其他线条样式影响的边框会受到影响(我认为了解这背后的全部原因是相当技术性和复杂性的!)。

在这个例子中,红色边框的单元格被1 px solid red应用了,但是因为粉色边框td只有指定的颜色,所以底部边框(它是tableand的一部分tr)不受影响,等等。

于 2012-08-17T11:35:45.093 回答
0

@Raj - 查看Mozilla 开发人员网站以获取基本信息,并在您尝试了一些事情后提出问题。

顺便说一句,这与@Arun P Johny 的答案类似,但使用 Jquery 实现:http ://codepen.io/5arx/pen/djhJE

于 2012-08-17T11:27:45.173 回答