[英]Why is the result of the multiplication not seen from the template with javascript but when inspecting the element in chrome dev tools it is?
i'm combining with my django project some javascript to do the calculations of a system.我正在与我的 django 项目结合一些 javascript 来进行系统的计算。 However, it seems strange to me that something as simple as the result of a multiplication is not reflected in the template of my web page but in the chrome dev tools然而,对我来说,像乘法这样简单的东西没有反映在我的网页模板中,而是反映在 chrome 开发工具中,这对我来说似乎很奇怪
I attach some images, in the first the total of the multiplication is not reflected, in the second the result of the multiplication is seen but with the chrome dev tools我附上一些图像,第一个没有反映乘法的总数,第二个看到乘法的结果,但使用 chrome 开发工具
here you do not see the result of the multiplication在这里你看不到乘法的结果
here you see the result of the multiplication在这里你可以看到乘法的结果
Parte/models.py部分/models.py
class Parte(models.Model):
codigo=models.IntegerField()
quantity=models.IntegerField()
unit_price=models.IntegerField()
total_price=models.IntegerField()
tax_free=models.BooleanField()
descripcion=models.TextField(max_length=255,blank=True, null=True)
descuento=models.IntegerField(default=0)
total=models.IntegerField(default=0)
# estatus = models.BooleanField()
# def __str__(self):
# return f'{self.codigo}: {self.estatus} {self.descripcion}'
def __str__(self):
return f'{self.codigo}: {self.descripcion} {self.quantity} {self.unit_price} {self.total_price} {self.tax_free}{self.descuento}{self.total}'
Parte/forms.py Parte/forms.py
class ParteForm(forms.ModelForm):
class Meta:
model=Parte
fields=['codigo','descripcion','quantity','unit_price','total_price','tax_free']
Presupuestos/models.py Presupuestos/models.py
class Presupuestos(models.Model):
parte=models.ForeignKey(Parte, on_delete=models.SET_NULL, null=True)
def __str__(self):
return f'{self.parte}'
calculos.js calculus.js
function multiplicar(){
var x=parseInt(document.getElementById('id_quantity').value);
var y=parseInt(document.getElementById('id_unit_price').value);
document.getElementById('id_total_price').innerHTML=x*y;
}
<td> {{presupuestosparteform.quantity}} </td> <td> {{presupuestosparteform.unit_price}} </td> <td> {{presupuestosparteform.total_price}} </td> <td> <div class="form-check"> {{presupuestosparteform.tax_free}} </div> </td> <td> <input type="button" class="btn btn-block btn-default" id="addrow" onclick="childrenRow()" value="+" /> </td> <td> <button type="button" onclick="multiplicar();">Button</button> </td>
The value of a input element can be settled by the value
attribute, not by innerHTML
: input 元素的value
可以由value
属性确定,而不是由innerHTML
:
function multiplicar(){
var x=parseInt(document.getElementById('id_quantity').value);
var y=parseInt(document.getElementById('id_unit_price').value);
document.getElementById('id_total_price').value = x * y;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.