您好我有这个JS功能的问题。我试图将一个String变量和html元素传递给JS函数,这样我就可以更改其他元素值。
JS
function resetSequence(biz_hrs,form){
var employees= [
{
"esc_hrs":"B"
"esc_resp":5004
"maximun":4
"minimun":1
}
{
"esc_hrs":"B"
"esc_resp":5005
"maximun":4
"minimun":1
}
{
"esc_hrs":"B"
"esc_resp":5006
"maximun":2
"minimun":1
}
{
"esc_hrs":"B"
"esc_resp":5007
"maximun":0
"minimun":0
}
{
"esc_hrs":"B"
"esc_resp":5054
"maximun":3
"minimun":1
},
];
for(var i = 0; i< employees.length; i++){
if(biz_hrs === employees[i].esc_hrs && form.value === employees[i].esc_resp ){
var f = document.escform;
f.sequence.max=employees[i].maximun;
f.sequence.val=employees[i].minimun;
}
}
HTML
<select id="p_escalation_resp_i" name="p_escalation_resp_i" class="validate[required]" onChange="resetSequence('B',this)">
<option value="5004">Database</option>
<option value="5005" selected >Application</option>
<option value="5006">Network Connectivity</option>
<option value="5007">Operating System Hardware</option>
<option value="5054">TEST</option>
</select>
<input type="number" name="p_escalation_sequence_i" id="sequence" value="1" step="1" min="0" max="" selected />
我的问题是Char参数B是否良好以及for cicle是否也很好
答案 0 :(得分:0)
您的问题不是很明确,但我可以推断您想要更改序列输入的最大值和最小值,对吗?
条件:
if(biz_hrs === employees[i].esc_hrs && form.value === employees[i].esc_resp ){
始终返回false,因为form.value
是String,employees[i].esc_resp
是整数。
然后尝试引用数组定义中的employees[i].esc_resp
值:
var employees= [
{
"esc_hrs":"B",
"esc_resp":"5004",
"maximun":4,
"minimun":1
},
{
"esc_hrs":"B"
"esc_resp":"5005"
"maximun":4
"minimun":1
},
{
"esc_hrs":"B",
"esc_resp":"5006",
"maximun":2,
"minimun":1
},
{
"esc_hrs":"B",
"esc_resp":"5007",
"maximun":0,
"minimun":0
},
{
"esc_hrs":"B",
"esc_resp":"5054",
"maximun":3,
"minimun":1
}
];
注意逗号(,)和引号(“”)。
适合我的完整代码:
<html>
<head></head>
<body>
<select id="p_escalation_resp_i" name="p_escalation_resp_i" class="validate[required]" onChange="resetSequence('B',this);">
<option value="5004">Database</option>
<option value="5005" selected >Application</option>
<option value="5006">Network Connectivity</option>
<option value="5007">Operating System Hardware</option>
<option value="5054">TEST</option>
</select>
<input type="number" name="p_escalation_sequence_i" id="sequence" value="1" step="1" min="0" max="" selected />
<script>
function resetSequence(biz_hrs,form){
var employees= [
{
"esc_hrs":"B",
"esc_resp":"5004",
"maximun":4,
"minimun":1
},
{
"esc_hrs":"B",
"esc_resp":"5005",
"maximun":4,
"minimun":1
},
{
"esc_hrs":"B",
"esc_resp":"5006",
"maximun":2,
"minimun":1
},
{
"esc_hrs":"B",
"esc_resp":"5007",
"maximun":0,
"minimun":0
},
{
"esc_hrs":"B",
"esc_resp":"5054",
"maximun":3,
"minimun":1
}
];
for(var i = 0; i< employees.length; i++){
if(biz_hrs === employees[i].esc_hrs && form.value === employees[i].esc_resp ){
var f = document.getElementById("sequence");
f.max=employees[i].maximun;
f.val=employees[i].minimun;
break;
}
}
}
</script>
</body>
</html>