0

我有一个 aui 选择字段(下拉),如果下拉选项更改,我想执行一些操作。

所以我的 aui 选择字段显示如下:

<form action="<liferay-portlet:actionURL name="saveInfo" />"

    <aui:select name="selectAmount" inlineLabel="true" label="select-amount" onChange="performOperationsOnInputField()">
        <aui:option value="0"></aui:option>
        <aui:option value="1">1</aui:option>
        <aui:option value="2">2</aui:option>
        <aui:option value="3">3</aui:option>
        <aui:option value="4">4</aui:option>
        <aui:option value="5">5</aui:option>
    </aui:select>

</form> 

脚本是:

<script type="text/javascript">
     function performOperationsOnInputField() {
         var portletNamespace = '<portlet:namespace />';
         var selectedValue = $('#selectAmount').val();

         if(selectedValue == '0') {
            // set a java variable value which can be access fro any java file(like static variable) or any best way so that we can access it from any java/jsp file

            });                   
        } 
    }
</script>   

我们可以从脚本中设置一个 java 变量值,以便我们可以从任何 java 文件和任何 jsp 页面全局访问此字段的值吗?

4

3 回答 3

1

// set a java variable value which can be access fro any java file(like static variable) or any best way so that we can access it from any java/jsp file

No you cannot.

You might misunderstand that JSP and JavaScript existed on same document. Yes but JSP part compiles on server side itself comes to client.

Javascript Plays on client side and JSP plays on server side.

What you need to do is you have to make a server request. And send that string as a query parameter or form or Ajax.

于 2013-10-15T06:28:52.270 回答
0

您可以使用基于 ajax 的调用,并且可以通过附加到 queryString 中来传递值

于 2013-10-22T13:43:21.783 回答
0

对服务器进行基于 ajax 的调用会将您的数据从 java-script 传递到 java。

于 2013-10-22T13:35:29.567 回答