如何通过JavaScript设置输入隐藏字段的值? [英] How to set the value of a input hidden field through JavaScript?
本文介绍了如何通过JavaScript设置输入隐藏字段的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试调用 resetyear
函数,并且该函数也被调用,但是流程在 alert("over")
处停止.它不会将其控制权转移给 resetmaster
.
I am trying to call the resetyear
function and it's getting called also, but the flow stops at alert("over")
. It doesn't transfer its control to resetmaster
.
String flag = "";
flag = (String) session.getAttribute("flag");
System.out.println("flag = " + flag);
if (flag == null) {
flag = "";
}
if (flag.equals("yes")) {
%>
<script>
alert(1);
// resetyear();
dontreset();
//document.getElementById("checkyear").value = "1";
//alert(document.getElementById("checkyear").value);
</script>
<%} else if(flag.equals("no"))
{%>
<script>
alert(2);
//document.getElementById("checkyear").value = "2";
//alert(document.getElementById("checkyear").value);
resetyear();
</script>
<%}else{}%>
function resetyear(){
if(confirm("DO YOU WANT TO RESET THE YEAR?"))
{
alert("hello");
//document.forms['indexform'].action = "resetmaster";
//alert(document.forms['indexform'].action);
//document.forms['indexform'].submit();
alert("over");
form.action = "resetmaster";
form.submit();
alert(1);
}
推荐答案
对我来说有效:
document.getElementById("checkyear").value = "1";
alert(document.getElementById("checkyear").value);
也许您的JS没有执行,您需要在其周围添加一个function(){}.
Maybe your JS is not executed and you need to add a function() {} around it all.
这篇关于如何通过JavaScript设置输入隐藏字段的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文