javascript - 如何从div中获取一个数字然后相乘
问题描述
我的结果如下 显示 50 个条目中的 5 到 40 个我需要获得总条目忽略“显示 5 到 40 个”并保持数字“50”将其插入输入总数然后乘以 10
<div class="info" id="info">Showing 30 to 40 of 50 entries</div>
<input type="text" id="total" name="total">
<input type="text" id="total" name="x10">
解决方案
这个答案强烈假设文本始终显示“显示 50 个条目中的 5 到 40 个”或类似文本,您还需要更改其中一个框的 id,因为所有 id 都应该是唯一的才能使用在js代码中
// use js to get the value
const info = document.getElementById("info").innerHTML
// get an array of text seperated by space
const texts = info.split(" ")
// get the 2nd last character
const number = parseInt(texts[texts.length - 2])
// put those values into the input boxes
document.getElementById("total").value = number
document.getElementById("totalTimes10").value = number*10
<div class="info" id="info">Showing 30 to 40 of 50 entries</div>
<input type="text" id="total" name="total">
<input type="text" id="totalTimes10" name="x10">
推荐阅读
- drake - 使用 Python 序列化 Drake 对象
- python - Python 3.6 将字典转换为排序列表
- c# - WinDBG Preview - 从其他 Visual Studio 项目加载源代码
- python - 如何知道 GEKKO 花了多长时间解决我的模型?
- ios - 加载类时 UITableViewCell UIView 颜色不会立即更改
- azure - Update-AzureRmVmss、Update-AzureRmVmssInstance 和 Update-AzureRmVmssVM 有什么区别?
- azure-devops - Azure Devops - 用户故事描述/接受标准字段中的 Markdown 支持?
- oracle - Oracle APEX - 默认主键值“t1000”
- c++ - 等待 MPI-IO 在 MPI_File_open 上同步的进程旋转
- javascript - 使 Google Chrome 浏览器图标在任务栏上闪烁