1

我正在使用 Liferay 门户 6.1.1 CE。

在我的 liferay portlets jsp 页面view.jsp中,我有一个带有 2 个文本字段和 2 个单选按钮(用户只能选择一个)和一个提交按钮的表单。

当我单击任何单选按钮时,控制转到正常工作的脚本函数。

现在我想将 2 个文本字段的值传递给脚本函数。我尝试了很多,但没有用。

我怎样才能做到这一点?

帮助我..提前谢谢。

<script>
    function dif()
    {

    }
</script>
<form name="<portlet:namespace/>fm" method="post" action="<%=updateBookURL.toString()%>">
    <table>
        <tr>
            <th>Leave Application</th>
        </tr>
        <tr>
            <td>Employee <font color=red>*</font></td>
            <td>
                <input type="text" name="<portlet:namespace/>name"/>
                <input type="text" name="<portlet:namespace/>eid"  />
        </tr>

            <td>
                Date <font color=red>*</font>
                <input type="text" id="<portlet:namespace/>fd" name="<portlet:namespace/>
            </td>
            <td>
            <input type="radio" name="<portlet:namespace/>f" id="f" value="1st half" onClick="f()"/>
            First Half&=
            <input type="radio" name="<portlet:namespace/>f" id="f" value="2ndhalf" onClick="f()"/>
            Second Half
            </td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" value="save data" size="100px"/></td>
        </tr>
    </table>
</form>
4

2 回答 2

3

在 javascript 函数中获取文本的值在 liferay 中并不是什么新鲜事,它是普通的旧 javascript,以下是一些可以帮助您的链接和示例(我编写的代码将进入您在<script> ... </script>标签中定义的自定义函数中):

  1. 使用以下方法获取输入文本值

    var fdTextValue = document.getElementById("<portlet:namespace/>fd").value;
    
  2. 使用 jQuery 获取输入文本值(唯一的问题是您必须在 portlet 或主题中包含 jQuery 库,因为从 Liferay-6 开始,您默认包含 Alloy UI):

    var fdTextValue = $("#<portlet:namespace/>fd").val();
    /* or */ 
    var fdTextValue = $("#<portlet:namespace/>fd").attr('value');
    
  3. 使用Liferay 的 Alloy UI获取输入文本值:

    AUI().use(function(A) {
        var fdTextValue = A.one('#<portlet:namespace/>fd').get('value');
        /* or */ 
        var fdTextValue = A.one('#<portlet:namespace/>fd').val();
    });
    

    以下一些链接也可能有助于您使用 Alloy UI:

    1. 使用 Alloy UI 处理元素和事件
    2. 合金 UI API
于 2012-12-11T08:05:06.163 回答
0

这很简单。

然后在 js 中的单击事件上定义此函数。

<script>
function callFun()
{
      // Here you can use jquery easily
      var name = $("#name").val();
      alert(name);
}
</script>
于 2014-01-31T11:30:26.100 回答