我在尝试从表单内的按钮元素调用 js 函数时头昏脑胀,这是我的代码:
<%
PortletPreferences prefs = renderRequest.getPreferences();
String employee = (String)prefs.getValue("name", "New Employee");
%>
<portlet:actionURL var="callURL" windowState="<%=LiferayWindowState.EXCLUSIVE.toString() %>" />
<script type="text/javascript">
Liferay.provide(window, 'insertEmployee',
function ()
{
var A = AUI();
var url = 'http://localhost:8080/c/portal/json_Service';
A.io.request(url,
{
method:'POST',
data:
{
serviceClassName: 'com.liferay.test.service.TrabajadorServiceUtil',
serviceMethodName: 'create',
servletContextName: 'TrabajadorPlugin-portlet',
serviceParameters: '[param]',
},
headers: {'Content-Type':'charset=utf-8'},
on:
{
success: function()
{
alert("success " + responseData.name);
}
},
form: {id: 'postForm'},
xdr: {dataType: 'json'}
});
},
['aui-io']
);
</script>
<div>
<aui:form name="postForm" id="postForm" method="post" onSubmit="insertEmployee();">
<input type="text" name="param" value="<%=employee %>"/>
<input type="submit" value="Submit"/>
</aui:form>
</div>
我没有使用 java 类,因此我也没有使用 portlet:actionURL。
我的意图是在单击“提交”按钮时调用“insertEmployee()”,但它仅发送用户在文本字段中插入的参数。我试图将“onsubmit”也放在提交输入中,但给出了相同的结果。
如果您能帮助我或指导我解决问题,那就太好了!我在互联网上找不到好的信息/tuts,我不确定问题出在哪里或我还需要知道什么。
提前致谢!
最佳答案
我只需要:
<aui:script>
window.functionName = function ()
{
//code
};
</aui:script>
并从以下位置调用它:
<aui:form name="myform" action="javascript:functionName();">
<aui:input type="submit" name="Submit" value="Update"/>
</aui:form>
并且该函数是从表单标签中调用的。
关于javascript - javascript函数的Alloy UI问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9993628/