我在我的网页上使用字形图标加减引导。我想为这两个字形图标添加功能。点击加面板必须添加到容器上,点击字形图标减去单个面板必须删除。
我怎样才能做到这一点?我不知道如何在JAVA脚本中编码,即使是新的J查询。
你可以像调用其他dom对象一样调用这个函数
<div class="container">
<h2>Menu-up Glyph</h2>
<p>Menu-up icon: <span class="glyphicon glyphicon-plus"></span></p>
</div>
In js
$(".glyphicon-plus").click(function(){
alert("The paragraph was clicked.");
});
或其他方式
<p>Menu-up icon: <span onclick='alert("youClickedMe!");' class="glyphicon glyphicon-plus">
希望这个例子对你有帮助。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Tab Pane add remove example</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<h1>Tab pane exercise</h1>
<div class="row">
<div class="col-lg-4">
<p>Plus icon button to add pane:
<button type="button" class="btn btn-default btn-sm addPane">
<span class="glyphicon glyphicon-plus"></span> Plus
</button>
</p>
</div>
<div class="col-lg-4">
<p>Minus icon button to remove pane:
<button type="button" class="btn btn-default btn-sm removePane">
<span class="glyphicon glyphicon-minus"></span> Minus
</button>
</p>
</div>
</div>
<div class="row">
<div class="col-lg-12" id="target">
</div>
</div>
</div> <!-- /container -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script language="javascript">
var panel= $("<div id='myPanel' class='panel panel-default'><div class='panel-body'><p>ADD YOUR TEXT</p>");
$(document).ready(function() {
$(".addPane").click(function(){
$("#target").append(panel);
});
$(".removePane").click(function(){
$("#myPanel" ).remove();
});
});
</script>
</body>
</html>