0

我正在创建一个项目,用户输入一个名称,该名称会在框中弹出,但您可以单击以在对话框中获取更多信息。我的代码正在运行,但要让对话框正确显示完整信息,您需要在搜索字段中输入至少 4 个字符。我希望用户即使输入少于 4 个字符也能获得更多信息。见下文 :)

搜索画面

对话画面

下面是我的脚本,我希望这对某人有意义。:)

$(document).ready(function() {

    $('#search').click(function() {
        $(".artist").remove();  // removes the artist class to clear search
        var artists = "js/data.json"; // places the file link into variable

        $.getJSON( artists, function(data) { //  uses the variable to connect to json file
            console.log(data);  
            $.each( data, function( i, item ) { // loops through the json files to retrieve required info
            // section for artists brief intro 
            $("ul#artist").append( "<li class='artist'><span style='font-size:24px; font-weight:bold;color:red;'>"  + item.name  + 
                "</span><br/>" + item.reknown + 
                "<br/><button class='ui-btn' id='information'><a href='#dialog' data-role='button' id='dialog' data-transition='flip'>More Information</a></button></li>");
            }); // end of each function

            $('#search').first().one('keyup', function(){   
             $.each( data, function( i, item ) {    // loops through the json files to retrieve required info
            // section for artists dialog full profile data
            $("ul#artist2").append( "<li class='artist'><span style='font-size:24px; font-weight:bold;color:red;'>" + item.name + 
                "</span><br/> " + item.reknown + 
                "<br/><img class='profile' src='images/" + item.shortname + "_tn.jpg' />" + 
                "<br/><span style='font-size:18px; color:red; font-weight:bold'>Bio:</span><br> " + item.bio + "</li>"); 

                });  // end of information function
             }); // end of each function  
        }); // end of getJson function 
    });  // end of submit on click function

});  // end document ready function 
4

0 回答 0