我正在與我的 django 專案結合一些 javascript 來進行系統的計算。然而,對我來說,像乘法這樣簡單的東西沒有反映在我的網頁模板中,而是反映在 chrome 開發工具中,這對我來說似乎很奇怪
我附上一些影像,第一個沒有反映乘法的總數,第二個看到乘法的結果,但使用 chrome 開發工具
在這里你看不到乘法的結果

在這里你可以看到乘法的結果

單方面/ models.p ?
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
class ParteForm(forms.ModelForm):
class Meta:
model=Parte
fields=['codigo','descripcion','quantity','unit_price','total_price','tax_free']
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}'
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>
uj5u.com熱心網友回復:
輸入元素的值可以通過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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/348914.html
標籤:javascript Python html 姜戈
上一篇:在Djangomodelformset_factory中獲取當前用戶
下一篇:在Django模型的類Meta中定義models.Index或models.UniqueConstraint是否有任何意義,如果managed=False
