javascript 使用 jQuery 获取 Servlet 会话属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25479866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Servlet session attributes using jQuery
提问by lxcky
I have a raffle button that's being enabled or disabled based on Session Attributes I've set using Servlets.
我有一个抽奖按钮,它根据我使用 Servlet 设置的会话属性启用或禁用。
It should be disabled if either of this is true
如果其中任何一个为真,则应禁用它
- the
enBancCount
is equals to zero - It's not a valid day
- 该
enBancCount
是等于零 - 这不是一个有效的日子
Here is my code:
这是我的代码:
<button id="raffleBtn" type="submit"
${sessionScope.enBancCount == 0 || !sessionScope.validDay ? 'disabled' : ''}>
Raffle
</button>
I'm currently using JSP EL to add the disabled
attribute on the button based on the two conditions above. But now, before enabling it, I also have to check if majority attended on this raffle.
我目前正在使用 JSP ELdisabled
根据上述两个条件在按钮上添加属性。但是现在,在启用它之前,我还必须检查是否大多数人都参加了这次抽奖活动。
I added the following input fields for checking the attendance:
我添加了以下输入字段来检查出勤情况:
<input type="checkbox" name="attendance" value=""> ATTENDEE 1
<input type="checkbox" name="attendance" value=""> ATTENDEE 2
<input type="checkbox" name="attendance" value=""> ATTENDEE ...
<input type="checkbox" name="attendance" value=""> ATTENDEE 6
And changed the html for the raffle button to:
并将抽奖按钮的 html 更改为:
<button id="raffleBtn" type="submit" disabled>
Raffle
</button>
And added the following JQuery code:
并添加了以下 JQuery 代码:
$('[name=attendance]').change(function() {
if ($('[name=attendance]:checked').length >= 4
&& // CONDITION IF ENBANC CASE IS NOT ZERO
&& // CONDITION IF IT'S A VALID DAY) {
$('#raffleBtn').removeAttr('disabled');
} else {
$('#raffleBtn').attr('disabled', 'disabled');
}
});
My only problem is that I don't know how to get the value of enBancCount
and validDay
using JQuery.
我唯一的问题是我不知道如何获取enBancCount
和validDay
使用 JQuery的价值。
Please help?
请帮忙?
回答by Ken de Guzman
You can do like this
你可以这样做
var enBancAccount = "${sessionScope.enBancCount}";
var validDay = "${sessionScope.validDay}";