BootStrap點(diǎn)擊下拉菜單項(xiàng)后顯示一個(gè)新的輸入框?qū)崿F(xiàn)代碼
我的頁面上有一個(gè)下拉菜單,頁面上有一個(gè)文本輸入框,一個(gè)圖像上傳框,文本輸入框默認(rèn)是顯示的,而圖片上傳框是隱藏的.
假設(shè)下拉菜單有兩項(xiàng)A和B,我想實(shí)現(xiàn)這樣的效果:點(diǎn)擊A時(shí)顯示文本輸入框,隱藏圖像輸入框;點(diǎn)擊B時(shí)顯示圖像上傳框,隱藏文本輸入框,請(qǐng)問怎么實(shí)現(xiàn)?
用firebug調(diào)試的時(shí)候發(fā)現(xiàn)只有在加載html頁面的時(shí)候幾個(gè)click函數(shù)才會(huì)執(zhí)行,頁面加載好后點(diǎn)擊下拉菜單項(xiàng),這些斷點(diǎn)都不會(huì)被執(zhí)行,求解是怎么回事.
我的js代碼如下(定義在<head>部分中):
<script type="text/javascript">
//image_upload是圖片上傳框的id,最開始時(shí)把它隱藏
$(document).ready( function(){
$("#image_upload").hide();
}
);
//text_only是下拉菜單項(xiàng),我想這個(gè)函數(shù)來實(shí)現(xiàn)點(diǎn)擊這個(gè)菜單項(xiàng)時(shí)
//顯示文本輸入框text_input,隱藏圖片上傳框image_upload
$('#text_only').click(function(e){
$("#text_input").show();
$("#image_upload").hide();
e.stopPropagation();
}
);
/*
image_only是下拉菜單項(xiàng),點(diǎn)擊它時(shí)隱藏文本框,顯示圖片上傳框
*/
$('image_only').click(function(){
$("#text_input").hide();
$("#image_upload").show();
});
</script>
完整的代碼如下,怕上面的信息還不夠:
<!DOCTYPE html>
<html lang="en">
<head>
<title> hello,world</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--防止中文亂碼 -->
<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-fileupload.css" rel="stylesheet" media="screen">
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-fileupload.js"></script>
<style>
.center {
width : auto;
display : table;
margin-top:150px;
margin-left: auto;
margin-right: auto;
}
.text-center {
margin-top:30px;
display:table;
margin-left:auto;
margin-right:auto;
}
body{
margin:0;
background: url('img/955.jpg');
background-size: 1440px 800px;
background-repeat: no-repeat;
display: compact;
background-color: transparent;
}
.btn-large{
padding: 14px 34px;
}
</style>
<script type="text/javascript">
$(document).ready( function(){
$("#image_upload").hide();
}
);
$('#text_only').click(function(e){
$("#text_input").show();
$("#image_upload").hide();
e.stopPropagation();
}
);
$('image_only').click(function(){
$("#text_input").hide();
$("#image_upload").show();
});
$('supervised').click(function(){
$("#text_input").show();
$("#image_upload").show();
}
);
</script>
<script type="text/javascript">
</script>
</head>
<body>
<h1>hello,world</h1>
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li class="active">
<a href="#">首頁</a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" >
單模態(tài) <b class="caret"> </b>
</a>
<ul class="dropdown-menu" >
<li><a id="text_only" href="#">文本 </a> </li>
<li><a id="image_only" href="#">圖像 </a> </li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
多模態(tài) <b class="caret"> </b>
</a>
<ul class="dropdown-menu" >
<li><a id="supervised" href="#">有監(jiān)督 </a> </li>
<li><a id="unsupervised" href="#">無監(jiān)督 </a> </li>
</ul>
</li>
</ul>
</div>
</div><!-- end of navbar -->
<div class="center">
<form class="form-vertical">
<fieldset>
<input id="text_input" type="text" class="input-xxlarge search-query" placeholder="Text input">
</br>
<div id="image_upload" class="fileupload fileupload-new text-center" data-provides="fileupload">
<!-- <input type="hidden" value="" name=""> -->
<div class="input-append">
<div class="uneditable-input span3">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"></span>
</div>
<span class=" btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change</span>
<input type="file" />
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
<button type="submit" class="btn text-center btn-large btn-success"> Search </button>
</br>
</fieldset>
</form>
</div>
</div>
</body>
</html>
BootStrap點(diǎn)擊下拉菜單項(xiàng)后顯示一個(gè)新的輸入框?qū)崿F(xiàn)代碼,希望對(duì)大家有所幫助!
- 學(xué)習(xí)使用Bootstrap輸入框、導(dǎo)航、分頁等常用組件
- Bootstrap輸入框組件簡單實(shí)現(xiàn)代碼
- bootstrap輸入框組件使用方法詳解
- Bootstrap CSS組件之輸入框組
- Bootstrap基本組件學(xué)習(xí)筆記之input輸入框組(9)
- Bootstrap3 input輸入框插入glyphicon圖標(biāo)的方法
- bootstrap下拉列表與輸入框組結(jié)合的樣式調(diào)整
- bootstrap布局中input輸入框右側(cè)圖標(biāo)點(diǎn)擊功能
- 基于Bootstrap使用jQuery實(shí)現(xiàn)輸入框組input-group的添加與刪除
- Bootstrap輸入框組件使用詳解
相關(guān)文章
div+css布局的圖片連續(xù)滾動(dòng)js實(shí)現(xiàn)代碼
整理一個(gè)div+css圖片連續(xù)滾動(dòng)代碼,原理跟腳本之家之前發(fā)布的文章一樣。2010-05-05
JavaScript forEach的幾種用法小結(jié)
forEach()是JavaScript中一個(gè)常用的方法,用于遍歷數(shù)組或類數(shù)組對(duì)象中的每個(gè)元素,本文就來介紹一下JavaScript forEach的幾種用法小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下2023-11-11
前端請(qǐng)求并發(fā)和請(qǐng)求覆蓋的解決方法
最近在開發(fā)一些大屏,涉及到比較多的數(shù)據(jù)來源,接口也沒有做聚合,導(dǎo)致頁面需要調(diào)很多接口來填充頁面數(shù)據(jù),那么就會(huì)有接口并發(fā)的問題出現(xiàn),所以本文給大家介紹了如何解決前端請(qǐng)求并發(fā)和請(qǐng)求覆蓋,需要的朋友可以參考下2024-10-10
JavaScript數(shù)組操作學(xué)習(xí)之splice()函數(shù)入門與精通
這篇文章介紹了JavaScript數(shù)組操作中的splice()方法,詳細(xì)講解了其定義、語法和用法,并通過實(shí)例展示了如何使用該方法進(jìn)行數(shù)組元素的添加、刪除和替換,需要的朋友可以參考下2024-11-11
JavaScript算法實(shí)例之求二叉樹從根到葉的所有路徑和
如果你希望求某一特定路徑(例如從根到葉子)上數(shù)字的和,那么問題就轉(zhuǎn)變?yōu)榱恕扒蠖鏄鋸母饺~的所有路徑和”,所以本文給大家介紹了如何使用JavaScript求二叉樹從根到葉的所有路徑和,需要的朋友可以參考下2023-10-10
js動(dòng)態(tài)生成表格(節(jié)點(diǎn)操作)
這篇文章主要為大家詳細(xì)介紹了js動(dòng)態(tài)生成表格,進(jìn)行節(jié)點(diǎn)操作,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01
javascript實(shí)現(xiàn)小型區(qū)塊鏈功能
這篇文章主要介紹了javascript實(shí)現(xiàn)小型區(qū)塊鏈功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

