空值来自javascript

时间:2013-03-15 08:37:12

标签: javascript jquery

这是我的javascript

<script type="text/javascript">
jQuery = $.noConflict();
function onCheck(){
  var rowvalues=jQuery(".rowvalues").val();
  alert(rowvalues);

}  
</script>

我的页面是

<type input="hidden" value="{!rowNum}" class="rowvalues" name="rowvalues" /> 

在rowNum中我的值为100.但在我的警报中它显示空值。不知道为什么。请帮助

2 个答案:

答案 0 :(得分:4)

你的HTML方式错误:

<type input="hidden"

应该是

<input type="hidden"

此外,还不清楚你从哪里调用onCheck函数。在打电话之前,您确定页面已完全加载吗?

答案 1 :(得分:0)

也许尝试打印值而不设置变量以减少问题中的因素。

我在JQuery中有三种方法可以完成此任务

alert($('input#foo').val()); # If you add an ID
alert($('input[name=row values]').val());
alert($('input[type=hidden]').val());