2016-11-09 100 views
0

我試圖使用Twitter typeahead庫爲iFrame實現自動完成,以便當我開始在iframe中輸入時,建議應該開始顯示,但它不是。與iFrame一起使用Typeahead

HTML代碼

<!DOCTYPE html> 
<html> 
    <head> 
     <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
     <script type="text/javascript" src="http://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script> 
    </head> 
    <body> 
     <iframe id="editorArea-frame" style="width:100%; height:100%;" frameborder="0"></iframe> 
    </body> 
</html> 
<script type="text/javascript" src="iframe.js"></script> 

Javascript代碼

var editorFrame = $('#editorArea-frame')[0]; 

var html = ''; 

html += '<style type="text/css">pre { background-color: #eeeeee; }</style>'; 

html += '<style type="text/css">html,body { cursor: text; } #editorDiv { display: inline-block; height: 100%; width: 100%; overflow-y:scroll; outline: none;}</style>'; 

html += '<body></div><div id="editorDiv" contentEditable="true"></div></body>'; 

editorFrame.contentDocument.open(); 

editorFrame.contentDocument.write(html); 

editorFrame.contentDocument.close(); 

當我執行這段JavaScript代碼的iframe變成空白,它的身體變得empty.Can有人點我的我做錯了什麼?

$('#editorArea-frame').typeahead({ 
     source: function(typeahead, query) { 
     return ['alpha', 'beta', 'bravo', 'delta', 'epsilon', 'gamma', 'zulu']; 
     } 
    }); 

回答

0

您必須在輸入字段上應用預先輸入。 我也建議避免iframe,如果你可以。這可以爲你節省一些腦細胞。

+0

ive實施它成功..感謝您的幫助 –

+0

你是怎麼做的?我試圖做,但我不能@KartikJain – eagle