我在表单上有四个按钮。每当单击按钮之一时,我都希望javascript重定向到新页面,并根据单击的按钮来更改标题。我尝试使用window.document.write替换标题文本,但这没有用。这是我的代码:
$('#claimant_search_button', '#ca_search_button', '#emp_search_button',
'#ea_search_button')
{
if (this.id == 'claimant_add_button') {
window.location("https://dol-oalj-dev.entellitrak.com/etk-dol-oalj-dev/tracking.base.create.request.do?dataObjectKey=object.maintenanceForm&button=claimant");
} else if (this.id == 'ca_add_button') {
window.location("https://dol-oalj-dev.entellitrak.com/etk-dol-oalj-dev/tracking.base.create.request.do?dataObjectKey=object.maintenanceForm&button=ca");
} else if (this.id == 'emp_add_button') {
window.location("https://dol-oalj-dev.entellitrak.com/etk-dol-oalj-dev/tracking.base.create.request.do?dataObjectKey=object.maintenanceForm&button=emp");
} else if (this.id == 'ea_add_button') {
window.location("https://dol-oalj-dev.entellitrak.com/etk-dol-oalj-dev/tracking.base.create.request.do?dataObjectKey=object.maintenanceForm&button=ea");
}
}
这是我在重定向页面上的标题:
<h1 id ="title_form "style="margin-bottom: 25px;"> Maintenance Form </h1>
如果用户单击claimant_search_button。我希望页面重定向到:
然后将标题更改为“ Claimant Maintenance Form”
我注意到在每种情况下该URL都是相同的,并且我了解您希望浏览器对该URL进行完全重定向。因此,在我看来,最干净的解决方案是在您的URL中添加一个查询参数,其中包含所单击按钮的标识符。例子:
<a id="claimant_search_button" href="https://dol-oalj-dev.entellitrak.com/etk-dol-oalj-dev/tracking.base.create.request.do?dataObjectKey=object.maintenanceForm&button=claimant">Button text</a>
<!-- Other buttons here -->
请注意已添加到URL的button = claimant。这样,您就不需要Java脚本了。但是,您将需要它来获取URL中的按钮查询参数并相应地设置标题。
编辑:在目标页面中:
var button_name = getParameterByName('button');
if(button_name=="claimant"){
document.getElementById("title_form").innerText = "Claimant Maintenance Form";
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
url = url.toLowerCase(); // This is just to avoid case sensitiveness
name = name.replace(/[\[\]]/g, "\\$&").toLowerCase();// This is just to avoid case sensitiveness for query parameter name
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句