我正在尝试在我的Liferay URL中附加一些变量,我现在调用了serveResorce,问题是我想用它附加一些值,值应为$(&#39; #id).val ()使用该URL,如何做到这一点,因为当我硬编码值为url然后它正在工作,但我想要一个可以是动态的值将在那里,如何做到这一点,就像我发布我的代码< / p>
<a href='#' onClick="location.href = '<portlet:resourceURL></portlet:resourceURL>&<portlet:namespace/>consultantID='+document.getElementById('LULU').value'&<portlet:namespace/>companyName='+document.getElementById('LULUComp').value+&<portlet:namespace/>type=createExcelForConsultant'">LULU</a>
这是工作正常的URL,7是去服务器但是我想在7的位置放置一个$(&#39; #id).val(),怎么做那个人请帮忙
答案 0 :(得分:3)
您将+7+
替换为:
+ document.getElementById('id').value +
答案 1 :(得分:1)
此方案中的一个好习惯是通过Liferay的javascript API创建URL,如下所示:
点击事件调用javascript方法:
<a href='#' onClick="onClickLULU();">LULU</a>
Javascript方法:
function onClickLULU(){
var consultantID = document.getElementById('LULU').value;
var companyName = document.getElementById('LULUComp').value;
var resourceURL = Liferay.PortletURL.createResourceURL();
resourceURL.setParameter("consultantID", consultantID);
resourceURL.setParameter("companyName", companyName);
resourceURL.setParameter("type", "createExcelForConsultant");
location.href = resourceURL;
}