我想为输入类型的特定值制作一个清除/重置按钮。 我试图为它创建一个js函数,但该函数清除了输入类型的所有值。 这是我的HTML:
std::string Socket::recv(const int bufSize, SF::recv flags) const
{
auto buffer = std::make_unique<char[]>(bufSize + 1);
auto recvd = 0, count = 0;
std::string str;
str.reserve(bufSize);
do {
// ONLY THIS PART IS DIFFERENT
const auto f = static_cast<int>(flags);
recvd = ::recv(sockfd, buffer.get() + count, bufSize - count, f);
// ONLY THIS PART IS DIFFERENT
count += recvd;
if (count == bufSize) {
str.append(buffer.get());
str.reserve(str.length() + bufSize);
std::memset(buffer.get(), 0, bufSize);
count = 0;
}
} while (recvd > 0);
str.append(buffer.get(), count);
if (recvd == -1) {
// TODO: Check for recvd == EAGAIN or EWOULDBLOCK and
// don't throw exception in that case.
throw std::runtime_error("Error occurred while writing message");
}
return str;
}
这是我的js功能:
<div id="wrapper-body">
<div id="kiri" class="btn btn-default">
<div id="kiri1">
<div class="btn btn-default">
<form action="../php/termo_i.php" id="form_input" method="post">
<table border=0>
<tr>
<td width=70>Tanggal</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="datepicker" type="text" name="datepicker" size=26> </td>
<td width=1>
<input type="text" id="t1" name="t1" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Silo</td>
<td width=10>:</td>
<td width=30>
<select name="silo" onchange="updateField(this.name, this.value)">
<option>-</option>
<option value="Silo 1">Silo 1</option>
<option value="Silo 2">Silo 2</option>
<option value="Silo 3">Silo 3</option>
<option value="Silo 4">Silo 4</option>
<option value="Silo 5">Silo 5</option>
<option value="Silo 6">Silo 6</option>
<option value="Silo 7">Silo 7</option>
<option value="Silo 8">Silo 8</option>
<option value="Silo 9">Silo 9</option>
<option value="Silo 10">Silo 10</option>
<option value="Silo 11">Silo 11</option>
<option value="Silo 12">Silo 12</option>
<option value="Silo 13">Silo 13</option>
<option value="Silo 14">Silo 14</option>
<option value="Silo 15">Silo 15</option>
<option value="Silo 16">Silo 16</option>
</select>
<input type="text" name="silo" size="16" readonly="readonly" id="silo">
</td>
<td width=1>
<input type="text" id="S1" name="S1" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 1</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s1" type="text" name="s1" maxlength="5" size=26 onkeyup="check();"> </td>
<td width=1>
<input type="text" id="l1" name="l1" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 2</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s2" type="text" name="s2" maxlength="5" size=26 onkeyup="check1();"> </td>
<td width=1>
<input type="text" id="l2" name="l2" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 3</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s3" type="text" name="s3" maxlength="5" size=26 onkeyup="check2();"> </td>
<td width=1>
<input type="text" id="l3" name="l3" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 4</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s4"type="text" name="s4" maxlength="5" size=26 onkeyup="check3();"> </td>
<td width=1>
<input type="text" id="l4" name="l4" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 5</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s5" type="text" name="s5" maxlength="5" size=26 onkeyup="check4();"> </td>
<td width=1>
<input type="text" id="l5" name="l5" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr> <tr>
<td width=70>Sensor 6</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s6" type="text" name="s6" maxlength="5" size=26 onkeyup="check5();"> </td>
<td width=1>
<input type="text" id="l6" name="l6" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr> <tr>
<td width=70>Sensor 7</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s7" type="text" name="s7" maxlength="5" size=26 onkeyup="check6();"> </td>
<td width=1>
<input type="text" id="l7" name="l7" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 8</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s8" type="text" name="s8" maxlength="5" size=26 onkeyup="check7();"> </td>
<td width=1>
<input type="text" id="l8" name="l8" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr> <tr>
<td width=70>Sensor 9</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s9" type="text" name="s9" maxlength="5" size=26 onkeyup="check8();"> </td>
<td width=1>
<input type="text" id="l9" name="l9" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr> <tr>
<td width=70>Sensor 10</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s10" type="text" name="s10" maxlength="5" size=26 onkeyup="check9();"> </td>
<td width=1>
<input type="text" id="l10" name="l10" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 11</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s11" type="text" name="s11" maxlength="5" size=26 onkeyup="check10();"> </td>
<td width=1>
<input type="text" id="l11" name="l11" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Sensor 12</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="s12" type="text" name="s12" maxlength="5" size=26 onkeypress="check11();onPress_ENTER();"> </td>
<td width=1>
<input type="text" id="l12" name="l12" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Ambien</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="amb" name="amb" value="35.0" readonly="readonly" type="text" size=26> </td>
<td width=1>
<input type="text" id="amb1" name="amb1" maxlength="5" size=1 disabled="disabled"style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Average</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="avr" name="avr" type="text" size=26 readonly="readonly"> </td>
<td width=1>
<input type="text" id="avr1" name="avr1" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Defiasi</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="deff" name="deff" type="text" size=26 readonly="readonly"> </td>
<td width=1>
<input type="text" id="deff1" name="deff1" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70>Status</td>
<td width=10>:</td>
<td width=30>
<input type="text" id="sts" name="sts" type="text" size=26 readonly="readonly"> </td>
<td width=1>
<input type="text" id="st1" name="st1" maxlength="5" size=1 disabled="disabled" style="visibility:hidden">
</td>
</tr>
<tr>
<td width=70></td>
<td width=10></td>
<td width=30>
<input class="btn btn-default" type="button" value="Ok" name="ok" id="ok"
<span id="result"></span>
<input class="btn btn-default" type="button" value="Reset" name="reset" id="reset" >
<input class="btn btn-default" type="button" value="Save" name="save">
<input class="btn btn-default" type="button" value="Delete" name="delete">
</td>
<td width=1>
<input class="btn btn-default" type="button" value="Print" name="print">
</td>
</tr>
</table>
</form>
</div>
</div>
<div id="btn btn-default" style="padding-left:350px">
<input class="btn btn-default" type="button" value="Edit" name="edit">
</div>
</div>
</div>
我尝试更改// JavaScript Document
$("#ok").click( function() {
$.post( $("#form_input").attr("action"),
$("#form_input :input").serializeArray(),
function(info){ $("#result").html(info);
});
clearInput();
});
$("#form_input").submit( function() {
return false;
});
function clearInput() {
$("#form_input :input").each( function() {
$(this).val('');
});
}
但它无效。我自己无法弄明白这个问题。
答案 0 :(得分:0)
function clearInput() {
var a=document.querySelectorAll("#form_input :input");
for(var i=0; i<a.length; i++){
a.value="";
}
}
&#13;
答案 1 :(得分:0)
对于每个特定输入,添加一个类cls
并更改您的clearInput()
功能,如下所示
function clearInput() {
$("#form_input .cls").each( function(){
$(this).val('');
});
}