2016-09-02 3 views
0

私のウェブページでブートストラップにグリフのアイコンプラスとマイナスを使用しています。この2つのグリフアイコンに機能を追加します。クリックしたときに とプラスのパネルをコンテナに追加し、グリフアイコンをクリックしてマイナスのパネルを削除する必要があります。絵文字にfuntionを追加する方法プラスとマイナスのinbootstrap-3

私はこれをどのように達成できますか?私はJavaスクリプトでコードする方法を正確にはわかりません。

答えて

0

あなたは、単に

<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"> 
0

私は、この例では、あなたの役に立てば幸い、他のDOMオブジェクトのような関数を呼び出すことができます。

<!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 --> 
 
\t <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 

 
\t <!-- Optional theme --> 
 
\t <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> 
 

 
\t 
 

 
    <!-- 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> 
 
\t <div class="container"> 
 

 
\t \t <h1>Tab pane exercise</h1> 
 

 
\t 
 
\t \t <div class="row"> 
 
\t \t \t <div class="col-lg-4"> 
 
\t \t \t \t <p>Plus icon button to add pane: 
 
\t \t \t \t \t <button type="button" class="btn btn-default btn-sm addPane"> 
 
\t \t \t \t \t \t <span class="glyphicon glyphicon-plus"></span> Plus 
 
\t \t \t \t \t </button> 
 
\t \t \t \t </p> 
 
\t \t \t </div> \t 
 
\t \t 
 
\t \t \t <div class="col-lg-4"> 
 
\t \t \t <p>Minus icon button to remove pane: 
 
\t \t \t \t <button type="button" class="btn btn-default btn-sm removePane"> 
 
\t \t \t \t <span class="glyphicon glyphicon-minus"></span> Minus 
 
\t \t \t \t </button> 
 
\t \t \t </p> 
 
\t \t \t </div> 
 
\t \t \t 
 
\t \t </div> \t 
 
\t \t 
 
\t \t <div class="row"> 
 
\t \t \t <div class="col-lg-12" id="target"> 
 
\t \t \t </div> 
 
\t \t </div> 
 
\t </div> <!-- /container --> \t 
 
\t \t 
 
\t <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
\t 
 
\t <!-- Latest compiled and minified JavaScript --> 
 
\t <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 
\t 
 
\t <script language="javascript"> 
 
\t 
 
\t var panel= $("<div id='myPanel' class='panel panel-default'><div class='panel-body'><p>ADD YOUR TEXT</p>"); 
 
\t 
 
\t 
 
\t 
 
\t $(document).ready(function() { 
 
\t 
 
\t \t \t $(".addPane").click(function(){ 
 
\t \t \t \t $("#target").append(panel); 
 
\t \t \t }); 
 
\t \t \t 
 
\t \t \t $(".removePane").click(function(){ 
 
\t \t \t \t $("#myPanel").remove(); 
 
\t \t \t }); 
 
\t \t \t 
 
\t \t \t 
 
\t 
 
\t }); 
 
\t 
 
\t </script> 
 
    </body> 
 
</html>

関連する問題