script:
function subNum(string){
var a = string;
alert(a);
}
html:
<input type="button" onclick="subNum(<%=rs.getString("name")%>)" >
无论参数为什么,打印出来为 object HTMLInputElement 。
但是当
html:
<input type="button" onclick="subNum(<%=rs.getInt("Id")%>)" >
时,可以正常打印出对应的数字。
这是什么情况呢,求解,难道js funtion的参数值不能为字符串?
onclick="subNum(<%=rs.getString("name")%>)" > 你这里没有用单引号,被认为为是一个变量名,所以你alert出来的是那个样子
如果想要是字符串,就要加单引号
参数当然可以是字符串,你别用alert输出了,
用console.log看看参数究竟是啥东西。
用引号快起参数,要不是传递变量名了,肯定是存在id和string遍历存的值一样的控件
<input type="button" onclick="subNum('<%=rs.getString("name")%>')" >
console.log 还是比较好用的