0

您好我有一种情况,我从 ajax 脚本返回的数据中显示了一些标签。我在 jsp 上已经存在另一个标签,它接受每个链接的 onClick 值。问题是在 jquery append 创建标签时没有设置 onclick 属性。

这是代码:-

$(document).ready(function() {
    $("#getResults").click(function(){

     $.post("getRefineSearchResultsPath", {bug:bug}, function(data) {

    var value = "<div id='list' class='attachment'>";
    value += "<ul class='unstyled'>";
    $issue.find('attachment').each(function(){

    var $attachment = $(this);
    value += "<li>";
    value += "<a href='#' onclick='document.f1.attachmentName.value='" +$attachment.find('attachmentName').text(); 
    value += "';document.f1.issueKey.value='"+$attachment.find('attachmentissueKey').text();
    value += "';document.f1.digest.value='"+$attachment.find('attachmentdigest').text();
    value += "';document.f1.submit();'>"+$attachment.find('attachmentName').text();
                                value += "</a>";
                                value += "</li>";
    });

    value +="</ul>";
    value +="</div>";

    $("#result").append(value);
    });
    });

});

我的 JSP 在这里:-

<html>
<body>

<button id="getResults" type="button" class="btn">Get</button>

<form name=f1 action="fetchAttachments" method="POST">
                    <input name=attachmentName type=hidden value=undefined> <input
                        name=issueKey type=hidden value=undefined> <input
                        name=digest type=hidden value=undefined>
                </form>

<div id="result">
&nbsp;
</div>

</body>
</html>

所以基本上在每个链接上点击表单应该被提交。如果我使用 JSTL 在 JSP 上呈现结果,这工作正常但是当我通过 Ajax 以 xml 形式获取数据结果时不起作用。总之,onclick 属性没有设置。知道可能是什么原因吗?谢谢

4

1 回答 1

0

看看生成了什么

<a href='#' onclick='document.f1.attachmentName.value='" +$attachment.find('attachmentName').text(); 

当它被渲染时

<a href='#' onclick='document.f1.attachmentName.value='someText'

您有报价问题。

于 2012-10-31T19:06:50.503 回答