<input>
的Id
前面的字符串_hospital_WAR_hospitalportlet_
不过是portlet命名空间。
此,如果您使用<aui:input>
标签只预置到您的<input>
的name
& id
属性,如果你只是用普通的香草HTML <input>
标签name
& id
属性没有改变。
但因为它是使用<aui:input>
,你可以做以下,以获得portlet的命名空间在你的JavaScript代码的好做法:
如果您使用的使用中<script> .. </script>
或JSP,即内部的JavaScript <aui:script> .. </aui:script>
然后你可以使用<portlet:namespace />
或<%= renderResponse.getNamespace() %>
在你的javascript里面得到字符串_hospital_WAR_hospitalportlet_
,就像。
jQuery("#<portlet:namespace />username").val();
// Or
jQuery("#<%= renderResponse.getNamespace() %>username").val();
但是,如果你使用的是*.js
文件,那么我建议你要把这个名字空间作为参数传递给JavaScript函数在js
文件:
function changeValues(portletNamespace) { // this function is in a js file
jQuery("#" + portletNamespace + "username").val("Lets change");
}
调用从JSP此功能:
<input type="button" onClick="changeValues('<portlet:namespace />')" />
希望这会有所帮助。我不知道是否有办法直接通过Liferay定义的某个JavaScript函数获取namespace
或portletId
。如果你有这样的东西,你可以在这里发布,这将是非常有益的。