我已经试过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