我正在尝试为一个隐藏的表单字段赋值,该值来自查询字符串参数。提取查询字符串参数的函数运行良好,但是将变量(使用document.forms)分配给隐藏的表单字段值属性的函数似乎不起作用,如果我检查元素,该值为空,但是如果我通过Chrome中的控制台运行它,它就会起作用。非常感谢。
从查找查询字符串的函数中获取变量:
var actionCode = getAllUrlParams().actioncode;
设置隐藏表单字段值:
function setHidden()
{
document.forms[0].action.value += actionCode;
return true;
}表单HTML:
<input id="field25" name="action" type="text" value="" class="field-size-top-large" disabled="disabled">实时页面在这里:http://exhibit.ubm-events.com/LP=83?cid=sm(n)_VIS_DRV20180515%7C1&actioncode=EMA1234
发布于 2018-05-30 17:33:11
尝试下面的代码
function setHidden(a,b){
return a*b;
}
document.getElementById('field25').value = setHidden(2, 3);发布于 2018-05-30 17:34:42
将actionCode变量传递给函数,这样它就一定在作用域内,并使用.getElementById,因为元素有一个ID。
function setHidden(actionCode)
{
document.getElementById("field25").value += actionCode;
return true;
}发布于 2018-05-30 17:38:15
您需要使用jquery选择元素并为其赋值
$("#field25").val("your value")参考http://api.jquery.com/val/#val2
https://stackoverflow.com/questions/50601142
复制相似问题