我有一个jsp,它链接到标签中的jquery 脚本文件。在此页面中,我有一个标签,当单击链接时,该标签必须从另一个 jsp 文件中加载。新页面中也有一定的jquery操作。但是当我加载页面时没有执行 jquery 操作,因此我也将 jquery 文件加载到新的 jsp 文件中。然后又出现了一个问题,即操作调用不止一次。请给出您宝贵的答复、建议和解决问题的方法...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Flyers</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/lib.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<script type="text/javascript" src="js/jquery.json-2.3.min.js"></script>
</head>
<div class="page_steps">
<s:form method="post" action="flyers" name='ldm_form' id='ldm_form_flyers'>
<!-- Question 1 -->
<div class="questionstep">
<div class="stepno">STEP 1</div>
<h2>Enter the correct DEC:</h2>
<input type="text" id="dec" name="oci.dec" value="" class="inputbx numericonly" maxlength="16" />
<div class="errbox">Please enter valid DEC</div>
<input type="button" value="" class="btn_continue" />
</div>
<!-- Question 2-->
<div class="questionstep">
<div class="stepno">STEP 2</div>
<h2>Select Your target program</h2>
<div class="errbox">Please select at lease one</div>
<s:iterator value="targetPrograms">
<input type="radio" name="tpId" value="<s:property value="tpId"/>"/><label id="<s:property value="tpId"/>"><s:property value="tpName"/></label><br/>
</s:iterator>
<input type="button" value="" class="btn_continue" />
</div>
<!-- Question 3 -->
<div class="questionstep">
<div class="stepno">STEP 3</div>
<h2>Select Your Mailing Materials</h2>
<div class="errbox">Please select at lease one</div>
<strong>Self Mailer</strong><br />
<div class="mailmaterials">
<ul class="questslider">
<s:iterator value="mailingmaterials" id="mailMat" begin="0" end="1">
<li>
<div class="quickpreview"><p>QUICK PREVIEW</p><div class="noshow">
<s:iterator value="#mailMat.templatePath" id="tempPath" begin="0" end="1">
<s:property value="#tempPath.ldmImgPath"/><s:property value="#tempPath.ldmImgName"/>,
</s:iterator>
</div></div>
<s:iterator value="#mailMat.templatePath" id="tempPath" begin="2">
<img src="<s:property value="#tempPath.ldmImgPath"/><s:property value="#tempPath.ldmImgName"/>" width="90" height="149" alt="" />
</s:iterator>
<br />
<label>
<input type="radio" name="mailMatId" value="<s:property value="#mailMat.mailMatId"/>"/><s:property value="#mailMat.mailMatName"/></label>
</li>
</s:iterator>
</ul>
</div>
这是我的主要jsp页面,这里我只显示了必须动态更改的标题部分和标签,页面很大,上传我想这么多就足够了,
在我的第二个jsp页面中
<s:set name="tabNo" value="tabNo"/>
<s:if test="%{#tabNo==0}">
<s:form method="post" action="flyers" name='ldm_form' id='ldm_form_flyers'>
<!-- Question 1 -->
<div class="questionstep">
<div class="stepno">STEP 1</div>
<h2>Enter the correct DEC:</h2>
<input type="text" id="dec" name="oci.dec" value="" class="inputbx numericonly" maxlength="16" />
<div class="errbox">Please enter valid DEC</div>
<input type="button" value="" class="btn_continue" />
</div>
<!-- Question 2-->
<div class="questionstep">
<div class="stepno">STEP 2</div>
<h2>Select Your target program</h2>
<div class="errbox">Please select at lease one</div>
<s:iterator value="ordCaptAct.targetPrograms">
<input type="radio" name="tpId" value="<s:property value="tpId"/>"/><label id="<s:property value="tpId"/>"><s:property value="tpName"/></label><br/>
</s:iterator>
<input type="button" value="" class="btn_continue" />
</div>
<!-- Question 3 -->
<div class="questionstep">
<div class="stepno">STEP 3</div>
<h2>Select Your Mailing Materials</h2>
<div class="errbox">Please select at lease one</div>
<strong>Self Mailer</strong><br />
<div class="mailmaterials">
<ul class="questslider">
<s:iterator value="ordCaptAct.mailingmaterials" id="mailMat" begin="0" end="1">
<li>
<div class="quickpreview"><p>QUICK PREVIEW</p><div class="noshow">
<s:iterator value="#mailMat.templatePath" id="tempPath" begin="0" end="1">
<s:property value="#tempPath.ldmImgPath"/><s:property value="#tempPath.ldmImgName"/>,
</s:iterator>
</div></div>
<s:iterator value="#mailMat.templatePath" id="tempPath" begin="2">
<img src="<s:property value="#tempPath.ldmImgPath"/><s:property value="#tempPath.ldmImgName"/>" width="90" height="149" alt="" />
</s:iterator>
<br />
<label>
<input type="radio" name="mailMatId" value="<s:property value="#mailMat.mailMatId"/>"/><s:property value="#mailMat.mailMatName"/></label>
</li>
</s:iterator>
</ul>
</div>
在 jquery 文件中,我有这样的代码
$('.tab').click(function(){
$('.tabmenu').children().removeClass('active');
$(this).parent('li').addClass("active");
var tabIndex=$(this).parent('li').index();
alert(typeof jQuery);
changeTabHtml("tabMenuAction_forms.action", "tabNo="+tabIndex, '.page_steps');
changeTabHtml("tabMenuAction_steps.action", "tabNo="+tabIndex, '.orderprocess_steps');
changeTabHtml("tabMenuAction_headerCaption.action", "tabNo="+tabIndex, ".headercaption");
});
function changeTabHtml(urlLink, data, divClass){
$.ajax({
type: "POST",
url: urlLink,
data: data,
cache: false,
success: function(msg){
$(divClass).html(msg);
}
});
}
直到这里一切正常......第二页正在动态加载一切正常。但是当它加载时,“btn_continue”必须调用一些 jquery 函数,如下所示
$('#ldm_form_flyers .btn_continue').click(function(){
var getid = $('.btn_continue').index($(this));
switch(getid){
case 0:
var getval = $.trim($("input[name='oci.dec']").val());
if(getval=='' || getval.length!=16 || getval.match(/[^\d]/)){
$("input[name='oci.dec']").addClass('err');
$('.questionstep:eq('+getid+') .errbox').slideDown();
}
else{
$.getJSON("btn_continueAction?btn_continueId="+getid+"&oci.dec="+getval, function(data){
var isNext=data.savedInSession;
$('.stepsanswer').eq(getid).find('span').html(getval);
$("input[name='oci.dec']").removeClass('err');
$('.decanswer').html(getval);
if(isNext==true)
nextquestion(getid);
else
$('.questionstep:eq('+getid+') .errbox').slideDown();
});
}
break;
现在加载此功能后不起作用。因此,我也尝试在第二页中加载 jquery 文件,然后它工作正常,但它开始多次访问服务器,因为文件加载了两次,然后是 4 次,然后是 8 .. 最终我的应用程序变慢了向下。那么是否有任何方法可以防止文件的加载,或者任何解决方案为什么“btn_continue”在不加载第二个jsp中的jquery文件的情况下无法正常工作......??????