简体   繁体   English

其次通过按钮执行功能

[英]Second do function by press button

Why function dont want write to the demo pragraph for second press button with other value? 为什么函数不想写第二个按钮的演示文章与其他值?

 function check(x){ if (x == 0,100) {return 1;} else { return 25;}; } function test2() { var y,input; input = document.getElementById("input2").value; y = check(input); $("#demo2").html( y ); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="number" id="input2"> <button id="but" onclick ="test2()">Try it</button> <p id="demo2"></p> 

It's because your check() function always return 1 and your p is overwritten each time you press the button. 这是因为你的check()函数总是返回1,每次按下按钮都会覆盖你的p。

what do you want to achieve in your if() ? 你想在if()中实现什么?

EDIT 编辑

Change your if to 改变你的if

if (x != '' && (x == 0 || x == 100))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM