我已經試過jQuery
select2
jQuery的選擇2和Ajax
http://ivaynberg.github.io/select2/
,它是如預期運行。
但是,我的選擇有700多個選項,我不想在用戶希望使用選擇框之前加載它們。
所以,我想顯示選擇框只有當用戶點擊一個按鈕。
<html>
<head>
<title>jQuery Load of Script</title>
</head>
<body>
<div id="showselect">
<button onclick="showselect()">select category</button>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
function showselect() {
document.getElementById('showselect').innerHTML='loading...';
$('#showselect').load('select1.htm');
$.getScript("select2.js");
$(".chzn").select2({width:230});
}
</script>
</body>
</html>
select1.htm
包含CSS樣式,以及選擇形式的html代碼:
http://likeforums.com/select1.htm
select2.js
從選擇2腳本拍攝,它是在這裏:
http://likeforums.com/select2.js
結果是這裏:
http://likeforums.com/test-select3.htm
單擊按鈕時,它只是顯示選擇框,並且select2
不起作用。
請幫忙。
感謝
腳本成功加載並執行後調用'select2()'。檢查下面的答案。 – 2013-04-09 10:43:47