在javasscript中使用setattribute函数中的变量

Rav*_*yay -1 html javascript php jquery javascript-events

显示NoN而不是城市名称.我试过以下代码 -

<script type="text/javascript"  language="javascript" >
function submitcity(c){
document.getElementById("ct").setAttribute('value',+c);//displaying NoN
//document.cityform.submit();
alert(c);
}</script>
Run Code Online (Sandbox Code Playgroud)

在身体

<img src="images/reset.jpg" width="80" height="24" onclick="submitcity('bhopal');" />
<form  action="" method="post" name="cityform" style="display:none;">
<input type="hidden" name="city" id="ct" value="" /></form>
Run Code Online (Sandbox Code Playgroud)

chr*_*her 5

+c
Run Code Online (Sandbox Code Playgroud)

+在值之前放置将尝试将其转换为数字.你没有传递号码.你看到的是什么NaN.

+从变量后面删除.

document.getElementById("ct").setAttribute('value',+c);
Run Code Online (Sandbox Code Playgroud)

document.getElementById("ct").setAttribute('value',c);
Run Code Online (Sandbox Code Playgroud)