如何用EL表达式获取map的值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用EL表达式获取map的值相关的知识,希望对你有一定的参考价值。

<%
Map<Integer,Integer> map2=new HashMap<Integer,Integer>();
map2.put(9,19);
map2.put(8,18);
map2.put(7,17);
pageContext.setAttribute("mapjh2", map2);
%>
$mapjh2[9]

页面上没有输出19这个数字。这是为什么呢?

参考技术A <c:forEach var = 'item' items='$mapjh2'>
$item

</cforEach >
这样可以循环输出,但是指定输出 在页面是不可行的。只能在后台吧要输出的先选择好

如何用jQuery获得select的值

1.获取第一个option的值

$(‘#test option:first‘).val();

2.最后一个option的值

$(‘#test option:last‘).val();

3.获取第二个option的值

$(‘#test option:eq(1)‘).val();

4.获取选中的值

$(‘#test‘).val();

$(‘#test option:selected‘).val();

5.设置值为2的option为选中状态

$(‘#test‘).attr(‘value‘,‘2‘);

6.设置最后一个option为选中

$(‘#test option:last‘).attr(‘selected‘,‘selected‘);

$("#test").attr(‘value‘ , $(‘#test option:last‘).val());

$("#test").attr(‘value‘ , $(‘#test option‘).eq($(‘#test option‘).length - 1).val());

7.获取select的长度

$(‘#test option‘).length;

8.添加一个option

$("#test").append("<option value=‘n+1‘>第N+1项</option>");

$("<option value=‘n+1‘>第N+1项</option>").appendTo("#test");

9.添除选中项

$(‘#test option:selected‘).remove();

10.删除项选中(这里删除第一项)

$(‘#test option:first‘).remove();

11.指定值被删除

复制代码
$(‘#test option‘).each(function()

if( $(this).val() == ‘5‘)
$(this).remove();

);

$(‘#test option[value=5]‘).remove();
复制代码

12.获取第一个Group的标签

$(‘#test optgroup:eq(0)‘).attr(‘label‘);

13.获取第二group下面第一个option的值

$(‘#test optgroup:eq(1) : option:eq(0)‘).val();

14.根据option的值选中option

$("#sel option:contains(‘C‘)").prop("selected", true);

以上是关于如何用EL表达式获取map的值的主要内容,如果未能解决你的问题,请参考以下文章

JSP ELEL表达式 获取list长度/不用循环,EL在List中直接获取第一项的内容/EL获取Map的键,Map的值

EL表达式怎么获取Map的动态key?

EL表达式怎么获取Map的动态key?

el表达式

求高手 java一个查询得到的集合list 如何用jquery_ajax让el表达式使用到这个集合

在jsp中使用el表达式通过键获得后台的一个map<Long,String>的值