【发布时间】:2021-07-25 01:00:26
【问题描述】:
我正在做一个项目,我想在特定时间只插入一条记录。
例如:在项目中,客户只给承包商打分一次。(在施工期间)一旦他打分,他就不能再打分了。
我在网上查了一下,但没有找到我要找的东西。
现在我有 2 个想法。
1- 插入复选框并使其永久禁用,一旦评级完成(通过服务器端验证)。
2- 根据数字(如 7/10)进行评分并显示出来。
选择哪一个是击球手策略。
代码部分:
CheckBox 解决方案代码(Google 上没有关于服务器端验证的解决方案):
Checkbox: <input type="checkbox" id="myCheck">
<p>Click the "Try it" button to disable the checkbox.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("myCheck").disabled = true;
}
</script>
还在stackoverflow上检查了这个(但这不是我要找的):
[服务器端解决方案示例链接][1]
数解:
<table>
<tr><td>Rate Your Contractor (Out Of 10)</td><td><input id="intLimitTextBox"></td></tr>
</table>
<script>
function setInputFilter(textbox, inputFilter) {
["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
textbox.addEventListener(event, function() {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("oldValue")) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
} else {
this.value = "";
}
});
});
}
// Install input filters.
setInputFilter(document.getElementById("intLimitTextBox"), function(value) {
return /^\d*$/.test(value) && (value === "" || parseInt(value) <= 10); });
</script>
是否有任何php方式(或两种方式)来实现我的问题的解决方案?
PS:我不是很擅长网络开发,如果我做错了,请见谅。
【问题讨论】:
标签: php html css mysql validation