larry*wei 2015-07-30 09:37 采纳率: 0%
浏览 36

onclick功能出现问题

Hi I have written a GSP and Javascript code to perform on click remove file functionality.

JavaScript code

function remove(attachmentId) {
    $(document).ready(function(){
            $('.glyphicon-remove').click ( function(e){
                e.preventDefault();
                $(this).parent().parent().remove();

                $.ajax({
                           url: "${g.createLink(controller: "landing", action: "deleteSelectedFile")}",
                            data: {
                                    attachmentId: attachmentId
                            },
                            success: function(data){
                                    alert("Success");
                            }

                       });

                 });
            });

        }

GSP Code

               <g:each in="${fileList}" var="file">
                    <div>
                        <a href="#" onclick="remove('${file.attachmentId}')"> 
                        <span class="glyphicon glyphicon-remove"></span></a> 
                        <a href="/forms/landing/attachment/${file.attachmentId}" >${file.name}</a> 
                        </br>
                    </div>
                </g:each>

Groovy Code

def deleteSelectedFile() {
        String attachmentId= params.attachmentId
        activitiService.deleteAttachemnt(attachmentId)
    }

I am not getting why exactly it is taking double click for deleting the first record.

Please help me.

Note: Application is running in Internet Explorer.

  • 写回答

4条回答 默认 最新

  • weixin_33720186 2015-07-30 09:39
    关注

    I think removing the $(document).ready(function() {...}) part as well as $('.glypeicon-remove') part from the remove function but keeping the stuff happening inside of these untouched, should fix your problem.

    So your code should look like:

    JavaScript:

    function remove(attachmentId) {
        $(this).parent().parent().remove();
        $.ajax({
            url: '${g.createLink(controller: '
            landing ', action: '
            deleteSelectedFile ')}',
            data: { attachmentId: attachmentId },
            success: function (data) { alert('Success'); }
        });
    }
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型