我有两个JSP页面,第一页有这样的链接:
<a id="page-help" href="#"
onclick="'referToDamageAssessor.do?method=showInsurantInf
&insurantId='+<%=temp.getPolicy().getLegalInsurant().getLegalInsurantId()%>;">
<%=temp.getPolicy().getLegalInsurant().getFirmName()%>
</a>
第二页显示了带有JSP scriptlet标记的会话的操作数据。当用户单击链接时,我想在jQuery对话框中显示数据。我写了这段代码:
第一个JSP页面:
<a id="page-help" href="#"
onclick="'referToDamageAssessor.do?method=showInsurantInf&insurantId='+
<%=temp.getPolicy().getLegalInsurant().getLegalInsurantId()%>;">
<%=temp.getPolicy().getLegalInsurant().getFirmName()%>
</a>
这是我的jQuery对话:
$(document).ready(function() {
$('#page-help').each(function() {
var $link = $(this);
var $dialog = $('<div></div>').load($link.attr('href'))
.dialog({
autoOpen: false,
show: "fade",
hide: "fade",
modal: true,
title: $link.attr('title'),
width: 500,
height: 300
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
});
});
导入jquery1.9.1.js,jquery-ui.js,jquery-ui.css
jQuery对话框打开但是为空。
答案 0 :(得分:0)
上述锚标记中的onclick()
调用将触发某些Javascript调用,并且无法使用Java servlet,如代码中所示,并且覆盖默认行为不是很好的做法,也是&lt;%temp.getPolicy()%&gt;中onclick处理程序中的单个和双参数完全错误。调用在页面加载时呈现为Java页面的一部分,而不是作为Javascript函数返回值。
您可以尝试以下可能有效的操作 - 删除单引号和加号:
<a id="page-help" href="#" onclick="referToDamageAssessor.do?method=showInsurantInf&insurantId=<%=temp.getPolicy().getLegalInsurant().getLegalInsurantId()%>;"> <%=temp.getPolicy().getLegalInsurant().getFirmName()%> </a>
为什么不改变帮助锚点并使用参数调用函数?
帮助链接
<a href="#" onclick="showHelp('Report damage', 'referToDamageAssessor.do?method=showInsurantInf&insurantId=<%=temp.getPolicy().getLegalInsurant().getLegalInsurantId()%>');"> <%=temp.getPolicy().getLegalInsurant().getFirmName()%> </a>
<a href="#" onclick="showHelp('Report damage', 'referToDamageAssessor.do?method=showInsurantInf&insurantId=<%=temp.getPolicy().getLegalInsurant().getLegalInsurantId()%>');"> <%=temp.getPolicy().getLegalInsurant().getFirmName()%> </a>
帮助来电者
function showHelp(title, url)
{
var $dialog = $('<div></div>')
.load(url)
.dialog({
show: "fade",
hide: "fade",
modal: true,
title: title,
width: 500,
height: 300
});
}