Java 在基于id设置值时对jsp行为感到困惑

Java 在基于id设置值时对jsp行为感到困惑,java,javascript,jquery,jsp,spring-mvc,Java,Javascript,Jquery,Jsp,Spring Mvc,在我的jsp on readyfunction中,我正在为一些变量设置值 $(document).ready(function() { ........////some code....... var compCode=$('#companyCode').val(); ........////some code....... $("#countrySectorinMemInfo").val(countrySec); ........////some code....... }); 我的控

在我的jsp on readyfunction中,我正在为一些变量设置值

$(document).ready(function() {
........////some code.......
var compCode=$('#companyCode').val();
........////some code.......
$("#countrySectorinMemInfo").val(countrySec);   
........////some code.......
});
我的控制器返回一个值,比如ABC,我使用

<input type="hidden" value="${ABC}" id="companyCode">

假设,如果我的jsp有两个以上的字段具有与“countrySectorinMemInfo”相同的id

那么“$(“#CountrySectorInMinfo”).val(countrySec);”将如何工作

谁能给我解释一下


将设置两个值或仅设置最后一个值…?

中有多个具有相同ID的元素。未指定浏览器行为。给他们一个不同的ID。如果您需要一个公共选择器,请使用
名称

我同意@BalusC

您应该使用类名而不是ID。我认为所有的JavaScript库都有按类名获取元素的方法。 jQuery方法:

// Get all elements with class 'myclass'
var nodes = $('.myclass');
YUI 2.7.0选择器方式:

// Get all elements with class 'myclass'
var nodes = YAHOO.util.Selector.query('.myclass'); 
YUI 2.7.0 getElementsByClass方式:

// Get all elements with class 'myclass'
var nodes = YAHOO.util.Dom.getElementsByClassName('myclass');