开发者

using href in jquery script

i have written a jquery that populates a html table from data that stored in a json array. in one of the fields, i want to create a hyperlink for it.

The table displays a list of files with the properties of filename, id, type, size and os.

i want the filename property to be a hyperlink of my choosing but i am not sure why its not working with the code below. if i remove the ("a").attr() and just leave it as default, it will display the filename coloumn but if i add that function in the code the filename column disappears.

here is the code below:

 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script>
            var files = ${jsonArray}
            $(document).ready(function() {
           开发者_StackOverflow中文版     var table = $('<table border="1"/>').appendTo($('#somediv'));
                $(files).each(function(i, file) {
                    $('<tr/>').appendTo(table)
                        .append($('<td/>').text(file.FileObject.id))
                        .append($('<td/>').text( $("a").attr("file.FileObject.filename", "http://www.google.com/")   ))
                        .append($('<td/>').text(file.FileObject.type))
                        .append($('<td/>').text(file.FileObject.size))
                        .append($('<td/>').text(file.FileObject.os));
                });
            });
        </script>


$('<td/>').text( $("a").attr("file.FileObject.filename", "http://www.google.com/"))

should be

$('<td/>').html( $("<a>").text(file.FileObject.filename).attr("href", "http://www.google.com/"));


.append($('<td/>').text( $("a").attr("href", "http://www.google.com/")   ))


have u tried using file.FileObject.filename instead of "file.FileObject.filename" i mean remove ur ""

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜