HTML
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>图标选择插件fontIconPicker - 光年(Light Year Admin)后台管理系统模板</title>
<link rel="icon" href="favicon.ico" type="image/ico">
<meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
<meta name="author" content="yinqi">
<link href="http://lyear.itshubao.com/iframe/css/bootstrap.min.css" rel="stylesheet">
<link href="http://example.itshubao.com/demo/css/materialdesignicons.min.css" rel="stylesheet">
<link href="http://libs.itshubao.com/fontIconPicker/css/jquery.fonticonpicker.min.css" rel="stylesheet">
<link href="http://libs.itshubao.com/fontIconPicker/themes/bootstrap-theme/jquery.fonticonpicker.bootstrap.min.css" rel="stylesheet" />
<link href="http://lyear.itshubao.com/iframe/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header"><h4>图标选择插件 fontIconPicker</h4></div>
<div class="card-body">
<p>选择后可直接获取选择后的值。例如:<code>$("#icon-example").val();</code></p>
<input type="text" id="icon-example" name="icon-example" />
<span id="show-mdi"></span>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/jquery.min.js"></script>
<script type="text/javascript" src="http://libs.itshubao.com/fontIconPicker/jquery.fonticonpicker.min.js"></script>
</body>
</html>
JavaScript
jQuery(document).ready(function($) {
var font_element = $('#icon-example').fontIconPicker({
theme: 'fip-bootstrap'
});
$.ajax({
url: 'http://example.itshubao.com/demo/materialdesignicons.json',
type: 'GET',
dataType: 'json'
}).done(function(response) {
var fontello_json_icons = [];
$.each(response.glyphs, function(i, v) {
fontello_json_icons.push( v.css );
});
font_element.setIcons(fontello_json_icons);
}).fail(function() {
console.error('字体图标配置加载失败');
});
$(document).on('change', '#icon-example', function(){
console.log('fdsafdsa');
$('#show-mdi').html($(this).val());
});
});