如何添加功能到字形图标加上和减去inbootstrap-3

时间:2016-09-02 09:53:20

标签: twitter-bootstrap-3

我在我的网页上使用bootstrap中的字形图标加号和减号。我想为这两个字形图标添加功能。 点击加上一些面板必须添加到容器中,点击字形图标减去必须删除单个面板。

我怎样才能实现这一目标?我不知道如何使用JAVA脚本编写代码,甚至是J Query的新代码。

3 个答案:

答案 0 :(得分:0)

你可以像任何其他dom对象一样调用该函数

 <div class="container">
  <h2>Menu-up Glyph</h2>
  <p>Menu-up icon: <span class="glyphicon glyphicon-plus"></span></p>


</div>

在js

 $(".glyphicon-plus").click(function(){
    alert("The paragraph was clicked.");
});

或其他方式

<p>Menu-up icon: <span onclick='alert("youClickedMe!");' class="glyphicon glyphicon-plus">

答案 1 :(得分:0)

我希望这个例子可以帮助你。

&#13;
&#13;
<!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>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

/home/wirintco/Pictures/Selection_005.png enter image description here

想要为这些glyphicons添加功能

@Raoul M. @Vicky