我正在使用 Liferay 门户 6.1.1 CE。
在我的 liferay portlet 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>
最佳答案
在 javascript 函数中获取文本的值在 liferay 中并不是什么新鲜事,它是普通的旧 javascript,以下是一些可以帮助您的链接和示例(我编写的代码将进入您在<script> ... </script>
标签):
-
var fdTextValue = document.getElementById("<portlet:namespace/>fd").value;
Get input text value using jQuery (唯一的问题是你必须在你的 portlet 或主题中包含 jQuery 库,因为从 Liferay-6 开始你默认包含了 Alloy UI):
var fdTextValue = $("#<portlet:namespace/>fd").val(); /* or */ var fdTextValue = $("#<portlet:namespace/>fd").attr('value');
使用 Alloy UI of Liferay 获取输入文本值:
AUI().use(function(A) { var fdTextValue = A.one('#<portlet:namespace/>fd').get('value'); /* or */ var fdTextValue = A.one('#<portlet:namespace/>fd').val(); });
以下一些链接也可以帮助您使用 Alloy UI:
关于liferay portlet 中的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13800324/