0
我有一个设置selected = true的函数。我有一个国家的下拉列表。每个选项都有IDS美国,GER这样......Javascript document.getElementById(arg) - 对象为空或未定义
function nation(arg)
{
if (arg == '<?php echo $this->escape($this->user->get('country'));?>')
document.getElementById(arg).selected = true;
}
window.onload = nation('<?php echo $this->escape($this->user->get('country'));?>');
我'确保PHP代码返回我正确的国家,但JavaScript调试器说:
SCRIPT5007: Unable to set value of the property 'selected': object is null or undefined
这里有什么问题吗?
在客户端发送相关生成的Javascript代码,而不是服务器端脚本。 – duri