javascript - 为什么 text() 和样式。宽度在 Js 中不起作用?
问题描述
我有一个如下所示的 HTML,
<div id ="b1>
<i class="icon-clock"></i> <span class="font-weight-bold font-size-lg" id="currentTime"></span>
</div>
我无法current date and time
在特定的 Div中显示。
JS:
// To display Date and time
var target = document.getElementById('b1');
var today = new Date();
var date =
today.getFullYear() +
"-" +
(today.getMonth() + 1) +
"-" +
today.getDate();
var time =
today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date + " " + time;
$(target).find('#currentTime').text(dateTime); // It dosen't displays the current date and time
我需要一个关于如何添加Width
到进度条的解决方案,如下所示,
<div id = "b2">
<div class="progress">
<div class="progress-bar bg-success" id="div1"
style="width:0%">
</div>
<div class="progress-bar bg-warning" id="div2"
style="width:0%">
</div>
</div>
</div>
如果我在 JS 中使用以下内容。
var target = document.getElementById('b2');
d1 = $(target).find('#div1');
d2 = $(target).find('#div2');
d1.style.width = 78 + "%";
d2.style.width = 22 + "%";
我可以得到Uncaught TypeError: Cannot set properties of undefined (setting 'width')
。
无法获取进度条的宽度。如何将宽度添加到特定 div 内的进度条?
如何添加Current Date and time
到特定的 Id ?
有人可以帮忙吗?
非常感谢。
解决方案
推荐阅读
- sql - SQL Server 中的 Geohash 函数?
- asp.net-mvc - 如何在下拉列表框中获取所选项目
- javascript - 数据表过滤单元格内容而不是数据库值
- python - 如何在 Docker 中的项目之间共享 django 数据库模型
- python - Python 3.x UnitTest 模块禁用 SystemExit 堆栈跟踪输出
- kaa - Kaa IoT 0.10.1 或 0.11.0 是否有可用的沙盒?
- bash - 如何在蝙蝠测试中使用正则表达式匹配字符串?
- java - Jersey 客户端如何在不引起内存问题的情况下处理巨大的负载?
- java - 网络爬虫与 Html 解析器
- r - 仅在 r 中替换第一列中的特殊字符