简体   繁体   English

为什么从带有 javascript 的模板中看不到乘法的结果,但在 chrome 开发工具中检查元素时却看到了?

[英]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.

相关问题 如果不首先使用 Chrome 开发工具检查元素,则无法 select 谷歌 Chrome 控制台中的 DOM 元素 - Cannot select a DOM element in Google Chrome Console without inspecting the element first using Chrome Dev Tools 在有角度的应用程序中,通过chrome dev工具检查元素时,为什么看不到纯HTML? - In angular application, while inspecting an element via chrome dev tool, why do I not see pure html? JavaScript document.querySelector() 在 Chrome 开发工具中登录到控制台时不显示标签/元素 - JavaScript document.querySelector() not showing tag/element when logged to console in Chrome Dev Tools 像 JavaScript 中的 Chrome Dev Tools 一样突出显示 HTML 元素 - Highlight HTML element just like the Chrome Dev Tools in Javascript Chrome开发工具:从bookmarklet / Snippet访问DOM元素$ 0指针 - Chrome dev tools: Accessing the DOM element $0 pointer from bookmarklet/Snippet 从 chrome 开发工具获取 CSS 作为 JavaScript object 值 - get CSS from chrome dev tools as JavaScript object value 如何使用 JavaScript(来自 Dev Tools)在 Chrome 中保存完整页面? - How to save a complete page in Chrome using JavaScript (from Dev Tools)? Chrome开发工具中的选择元素不起作用? - Select element in Chrome Dev Tools not working? 无法使用Chrome开发工具检查元素 - Unable to Inspect an Element using Chrome Dev Tools 点击元素不会显示结果,Chrome开发者工具也不会显示错误 - Clicking an element doesn't display a result and chrome dev tools don't show an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM