[英]Need help getting the name of a included jsp page in javascript
我有一個.jsp頁面的代碼:
<f:view>
<div class="portletBody">
<h:form id="editSectionForm" onsubmit="return numCheck(document.forms[0].elements['editSectionForm:sectionTable:0:maxEnrollmentInput'].id)">
<sakai:flowState bean="#{editSectionBean}"/>
<t:aliasBean alias="#{viewName}" value="editSection">
<%@ include file="/inc/navMenu.jspf"%>
</t:aliasBean>
<h3><h:outputText value="#{msgs.edit_section_page_header}"/></h3>
<%@ include file="/inc/globalMessages.jspf"%>
<t:aliasBean alias="#{bean}" value="#{editSectionBean}">
<%@ include file="/inc/sectionEditor.jspf"%>
</t:aliasBean>
<t:div styleClass="act">
<h:commandButton
action="#{editSectionBean.update}"
value="#{msgs.update}"
styleClass="active"
onclick="reEnableLimits();" />
<h:commandButton action="overview" value="#{msgs.cancel}" immediate="true" />
</t:div>
</h:form>
</div>
</f:view>
並且我有一些在/inc/sectionEditor.jspf文件中運行的javascript代碼。 在sectionEdtior文件中的某些代碼中,我需要以某種方式獲取此表單的ID。 editSectionForm 。 我無法對其進行硬編碼,因為/inc/sectionEditor.jspf代碼可在多個頁面中運行。
差不多,我需要/inc/sectionEditor.jspf中的javascript代碼才能獲取當前所在表單的ID。
即:
如果我在editSectionForm頁面中,它將告訴我該頁面中的即時消息,如果我在addSectionForm頁面中,則表明我在該頁面中。
我不確定我是否完全理解這個問題。 您是否要獲取當前所在的頁面(如url)?
http://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/
還是在同一頁面上有多個表格?
實際上,我想出了另一種解決方法。 對於每個已使用過酒井的人,他們知道獸,它是。
我看到您已經在jsp頁面中使用document.forms[0]
,因此,假設僅存在一種表單,您也可以在“子頁面”的腳本部分中使用相同的構造,即使用document.forms[0].id
將為您提供表單的ID。
<!DOCTYPE html>
<html>
<body>
<form id="editSectionForm">
<div id="sectionEditor">
<script type="text/javascript">
var formId = document.forms[0].id;
console.log(formId);
</script>
</div>
</form>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.