我想将所有 span 标签的第一个字符转换为大写,但出现错误:TypeError: a[0].toUpperCase is not a function。
<div id="test">
<h1>
<span>test</span> <span>test</span> <span>test</span>
</h1>
</div>Run Code Online (Sandbox Code Playgroud)
var x = document.getElementById("test");
function capital(a)
{
return a[0].toUpperCase() + a.slice(1);
}Run Code Online (Sandbox Code Playgroud)
var test=x.getElementsByTagName("span");
var b=capital(test)
console.log(b)Run Code Online (Sandbox Code Playgroud)
我正在尝试按照 Django 导入导出库(外键小部件)的指南使用外键导入数据。但我收到以下错误,我尝试添加带有标题名称 id 的附加列,但仍然收到相同的错误。
Errors
Line number: 1 - 'id'
None, 46, 19, LSD
Traceback (most recent call last):
File "/var/www/vfsc-env/lib/python3.6/site-packages/import_export/resources.py", line 635, in import_row
instance, new = self.get_or_init_instance(instance_loader, row)
File "/var/www/vfsc-env/lib/python3.6/site-packages/import_export/resources.py", line 330, in get_or_init_instance
instance = self.get_instance(instance_loader, row)
File "/var/www/vfsc-env/lib/python3.6/site-packages/import_export/resources.py", line 318, in get_instance
self.fields[f] for f in self.get_import_id_fields()
File "/var/www/vfsc-env/lib/python3.6/site-packages/import_export/resources.py", line 318, in <listcomp>
self.fields[f] for f in self.get_import_id_fields()
KeyError: 'id'Run Code Online (Sandbox Code Playgroud)
这就是我所做的。
class Clockin_Users(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
userid …Run Code Online (Sandbox Code Playgroud)我有一个元组列表,我想遍历它并计算总成本。我想得到橙色的总成本加上香蕉的总成本。例如,5.26*8 + 2.00* 10找出总成本。
如何访问这些值?例如,我尝试访问,5.26 using b[1]*b[2]但出现错误。
def totalcost(shoping):
for a in shoping:
for b in a:
total1=b[1]*b[2]
print(total1)
shoping=[("orange",5.26,8),("banana",2.00,10)]
totalcost(shoping)
Run Code Online (Sandbox Code Playgroud)