js中获取了元素的id,想要根据id去做判断执行函数,可是获取的id类型是对象类型,转换之后也不能解决(初学者)

function onc1() {
var n = document.getElementById("z");
var x = n.value;
if (n == "q") {
fun(x);
} else if (n == "e") {
fun1(x);
} else {
fun2(x);
}
}

function onc1() {
var n = document.getElementById("z");
var x = n.value;
var id=n.getAttribute("id");
if (id == "q") {
fun(x);
} else if (id== "e") {
fun1(x);
} else {
fun2(x);
}
}

你的这个z如果是input标签,那这么写没问题,具体得看是什么标签,不然.value不一定可以获取到