我正在尝试将用户范围滑块输入转换为HTML形式,然后调用Java函数以进一步执行。直到调用JavaScript函数为止,它都可以正常工作,但是默认情况下,它只考虑第一个if
。
如果范围滑块输入大于等于100,或者如果滑块输入小于100,我希望它执行if语句。
<tr height=40>
<td width=40></td>
<td>
<form id="P1_pulsetime" oninput="">
<br><br>
10<input type="range" id="port1_pulseslider" min="10" max="120" value="20" onchange="pulserangevalueX.value=value"/>120
<output id="pulserangevalueX">20</output>
<br><br>
<input type="button" onclick="Port1_pulsetime()" value="Port_1_pulse">
<br><br>
</form>
</td>
</tr>
function Port1_pulsetime(){
if(connected_flag==1){
client.subscribe("lazy/test");
var P1_slider = document.getElementById("port1_pulseslider").value;
var pulserangevalueX = document.getElementById("pulserangevalueX").value;
if (pulserangevalueX >= '100') {
message = new Paho.MQTT.Message("PULSE 1" + document.getElementById("port1_pulseslider").value);
message.destinationName = "lazy/test";
client.send(message);
}
else if (pulserangevalueX < '100') {
message = new Paho.MQTT.Message("PULSE 10" + document.getElementById("port1_pulseslider").value);
message.destinationName = "lazy/test";
client.send(message);
}
}
else {
console.log("not connected")
}
return false;
}
我认为有一些小错误无法捕捉。
答案 0 :(得分:0)
尝试如下所示放置else,插入console.log()以查看是否输入else。
function Port1_pulsetime(){
if(connected_flag==1){
client.subscribe("lazy/test");
var P1_slider = document.getElementById("port1_pulseslider").value;
var pulserangevalueX = document.getElementById("pulserangevalueX").value;
if (pulserangevalueX >= '100') {
message = new Paho.MQTT.Message("PULSE 1" + document.getElementById("port1_pulseslider").value);
message.destinationName = "lazy/test";
client.send(message);
}
else if (pulserangevalueX < '100') {
message = new Paho.MQTT.Message("PULSE 10" + document.getElementById("port1_pulseslider").value);
message.destinationName = "lazy/test";
client.send(message);
} //INSERT ELSE HERE
else {
// INSERT CONSOLE LOG HERE
}
}
else {
console.log("not connected")
}
return false;
}