Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 增加不会显示结果_Javascript - Fatal编程技术网

Javascript 增加不会显示结果

Javascript 增加不会显示结果,javascript,Javascript,我是一个新人。我试图展示结果。我想知道是什么问题,并有一个解决办法。请帮帮我 Html 倍增 function eventClick(){ var field1, field2, resultat, txt = ''; field1 = parseInt(document.getElementById("prixUnitaireValue")).value; field2 = parseInt(document.getElementById("quantiteValue")).value; re

我是一个新人。我试图展示结果。我想知道是什么问题,并有一个解决办法。请帮帮我

Html

倍增

function eventClick(){
var field1, field2, resultat, txt = '';
field1 = parseInt(document.getElementById("prixUnitaireValue")).value;
field2 = parseInt(document.getElementById("quantiteValue")).value;
resultat = (field1 * field2);
正文

结果

document.getElementById("demo") = txt;

}

嗨,解决方案是这样的。。。如果要将结果呈现到html元素中,必须阻止表单提交

  • 从按钮中删除type=“submit”
  • 在单击处理程序中添加evt.preventDefault()
  • 带有parseInt的行被不直接地括起来
  • 简化了结果处理。。。没有文字内容的麻烦
HTML:

JS小提琴在这里:

function eventClick(){
var field1, field2, resultat, txt = '';
field1 = parseInt(document.getElementById("prixUnitaireValue")).value;
field2 = parseInt(document.getElementById("quantiteValue")).value;
resultat = (field1 * field2);
if (resultat.textContent) {
    txt = resultat.textContent;
} else if(resultat.innerText) {
    txt = resultat.innerText
} else {
    txt = '';
}
document.getElementById("demo") = txt;
    <form name="facturation" id="facturation">
        Prix unitaire <input type="text" name="prixunitaire" id="prixunitaire"/> €
        </br>
        Quantité <input type="text" name="quantite" value="1" id="quantite"/>
        </br>
        <button value="valider" id="myBtn">Valider</button>
        </br>
        <p id="demo"></p>
    </form>
    function eventClick(evt) {
        evt.preventDefault();
        var field1, field2, resultat, txt = '';
        field1 = parseInt(document.getElementById("prixunitaire").value);
        field2 = parseInt(document.getElementById("quantite").value);
        resultat = (field1 * field2);
        document.getElementById("demo").innerHTML = resultat;
        return false;
    };

    var x = document.getElementById("myBtn");
    if (x.addEventListener) {
    x.addEventListener("click", eventClick);
    } else if (x.attachEvent) {
    x.attachEvent("onclick", eventClick);
    }