javascript - jquery 动态内部 html

标签 javascript jquery html

我有一个带有周三周标题的事件日历,例如

<th class="fc-day-header fc-wed fc-widget-header">Wed</th>

<td class="fc-day fc-wed fc-widget-content fc-other-month fc-past" data-date="2014-02-26">
<td class="fc-day fc-wed fc-widget-content fc-past" data-date="2014-03-05">

我想将一些文本附加到days的内部html中。当尝试以下代码时

    var items = "SWERTY LOPES-014-256-9696",
    divs = document.getElementsByClassName('fc-wed');
    [].slice.call( divs ).forEach(function ( div ) {
    div.innerHTML = div.innerHTML+items;    
    });

它还更改了周标题。但我希望 weak header 内部 html 保持不变。 提前致谢。

最佳答案

使用querySelectorAll仅针对具有所述类的 td 元素

var items = "SWERTY LOPES-014-256-9696",
    divs = document.querySelectorAll('td.fc-wed');
[].slice.call(divs).forEach(function (div) {
    div.innerHTML = div.innerHTML + items;
});
<小时/>

自从用 jQuery 标记

var items = "SWERTY LOPES-014-256-9696";
$('td.fc-wed').html(function (i, html) {
    return html + items
})

关于javascript - jquery 动态内部 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22324290/

相关文章:

jquery - 如何同时给元素的所有子元素添加css样式?

javascript - 如何从有序列表中选择一个列表元素?

html - Mozilla Firefox 默认字体大小

javascript - jQuery/Ajax - 尝试通过 Ajax 创建 POST 方法并获取对 HTML 的响应

javascript - iframe获取可见大小

javascript - AngularJS - HTTP 请求在 Controller 中发出预检请求但不在 app.js 中

jquery - 可放置 - hoverClass

javascript - CSS/Jquery - 在移动设备/选项卡上查看时的导航下拉菜单

javascript - Jquery 预加载器动画有效,但它是一个噱头还是它实际上是在计算站点负载?

javascript - Youtube 视频作为着陆页的背景