从其他文本字段填充隐藏字段javascript
我试图通过使用javascript连接其他文本字段来填充隐藏字段(没有JQuery,只有纯javascript) 我下面的代码在Chrome和Firefox中运行得很好,但在IE 8,9,10中消失了从其他文本字段填充隐藏字段javascript,javascript,html,hidden,populate,Javascript,Html,Hidden,Populate,我试图通过使用javascript连接其他文本字段来填充隐藏字段(没有JQuery,只有纯javascript) 我下面的代码在Chrome和Firefox中运行得很好,但在IE 8,9,10中消失了 Javascript function buildhidden() { var joinedvalues = textfield_id_1.value+textfield_id_2.value+textfield_id_3.value; document.getElementById("hidd
Javascript
function buildhidden() {
var joinedvalues = textfield_id_1.value+textfield_id_2.value+textfield_id_3.value;
document.getElementById("hiddenfield_id").value = joinedvalues;
};
html输入文件
<input type="text" name="textfield_id_1" id="textfield_id_1" value="" maxlength="1" onKeyUp="buildhidden();">
这也不起作用。我是一个php开发人员,JS不是我的强大套件。。。任何帮助都是非常欢迎的。使用
document.getElementById('id here')
,因为所有浏览器不会将元素的id公开到全局范围
id.value // bad practice, not cross-browser
document.getElementById('id').value // good, cross browser
这样做:
function buildhidden() {
var joinedvalues = document.getElementById('textfield_id_1').value + document.getElementById('textfield_id_2').value + document.getElementById('textfield_id_3').value;
document.getElementById("hiddenfield_id").value = joinedvalues;
}
使用
document.getElementById('id here')
,因为所有浏览器都不会将元素的id公开给全局范围
id.value // bad practice, not cross-browser
document.getElementById('id').value // good, cross browser
这样做:
function buildhidden() {
var joinedvalues = document.getElementById('textfield_id_1').value + document.getElementById('textfield_id_2').value + document.getElementById('textfield_id_3').value;
document.getElementById("hiddenfield_id").value = joinedvalues;
}
在IE中,Id为的冒号可以转换为下划线,您可以使用以下方法:
function convertNameToId(strId)
{
reg = /:/g;
return strId.replace(reg, "_");
}
和使用:
document.getElementById(convertNameToId(strName))
在IE中,Id为的冒号可以转换为下划线,您可以使用以下方法:
function convertNameToId(strId)
{
reg = /:/g;
return strId.replace(reg, "_");
}
和使用:
document.getElementById(convertNameToId(strName))
你能提供更多的代码或一个新的版本吗?当我在IE8中尝试它时,它就像预期的那样工作,所以我认为你的问题可能在其他地方?你能提供一些更多的代码或解决方案吗?当我在IE8中尝试它时,它就像预期的那样工作,所以我认为你的问题可能在其他地方?遵循这个建议-使用上面的函数工作-绝对是范围问题遵循这个建议-使用上面的函数工作-绝对是范围问题