按钮点击文件未在html

时间:2017-12-13 03:48:25

标签: javascript php jquery html

这里div正在通过相应的php动态地从数据库获取数据。它正在检索文件名和标题并显示在每个div中。这些文件也通过相同的文件名保存在'/ testupload /'本地目录中,应该通过“查看详细信息”按钮单击文件名来获取文件名,用户可以查看该文件。但我未能实现这一点。当我点击按钮显示每个按钮的特定文件时,会发生什么。这是我的代码的Javascript部分。

    function view() {
    //location.href = "./testupload/"+nt_name;
    window.location='./testupload/'+nt_name; return false;

}

function dynamic3() {
    //alert(drName.length);
    for (var i = 0; i < total3; i++) {
        var d = new Array(6);
        //var i = 0;

        nt_name = notice_name\[index3\];
        nt_title = notice_title\[index3\];
        index3 = index3 + 1;
        //console.log(name + "      " + type + "      " + sal);
        //console.log(d\[0\] + d\[1\] + d\[2\] + d\[3\] + d\[4\]+ d\[5\]);
        var div = document.createElement('div');
        div.className = 'row';
        div.innerHTML = '<div class="container" >\
                    <div class="bs-calltoaction bs-calltoaction-info">\
                    <div class="row"\
                    <div class="col-sm-12">\
                    <div class="col-md-9 cta-contents">\
                     <h1 class="cta-title">Notice: ' + nt_name + '</h1>\
                     <div class="cta-desc">\
                     <h3>' + nt_title + '</h3>\
                    </div>\
                    </div>\
                    <div class="col-md-3 cta-button">\
                    <button type="button" class="btn btn-lg btn-block btn-info" onclick="view()">View Detail</button>\
                    </div>\
                    </div>\
                    </div>\
                    </div>\
            </div>';

        document.getElementById('notice_content').appendChild(div);
    }

}

Here goes the image of the web page

1 个答案:

答案 0 :(得分:2)

您是否试图告诉view()函数转到.PDF文件?如果是这样,我认为你打算用一个参数调用该函数,查看( nt_name )......不能看到你的其余代码就是肯定的。

function view(nt_name) {
    window.location='./testupload/'+nt_name; return false;
}

function dynamic3() {
    for (var i = 0; i < total3; i++) {
        var d = new Array(6);

        nt_name = notice_name\[index3\];
        nt_title = notice_title\[index3\];
        index3 = index3 + 1;

        var div = document.createElement('div');
        div.className = 'row';
        div.innerHTML = '<div class="container" >\
                    <div class="bs-calltoaction bs-calltoaction-info">\
                    <div class="row"\
                    <div class="col-sm-12">\
                    <div class="col-md-9 cta-contents">\
                     <h1 class="cta-title">Notice: ' + nt_name + '</h1>\
                     <div class="cta-desc">\
                     <h3>' + nt_title + '</h3>\
                    </div>\
                    </div>\
                    <div class="col-md-3 cta-button">\
                    <button type="button" class="btn btn-lg btn-block btn-info" onclick="view(\'' + nt_name + '\')">View Detail</button>\
                    </div>\
                    </div>\
                    </div>\
                    </div>\
            </div>';

        document.getElementById('notice_content').appendChild(div);
    }

}