BootStrap點(diǎn)擊下拉菜單項(xiàng)后顯示一個(gè)新的輸入框?qū)崿F(xiàn)代碼
我的頁(yè)面上有一個(gè)下拉菜單,頁(yè)面上有一個(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頁(yè)面的時(shí)候幾個(gè)click函數(shù)才會(huì)執(zhí)行,頁(yè)面加載好后點(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ù)來(lái)實(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="#">首頁(yè)</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="#">無(wú)監(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)航、分頁(yè)等常用組件
- Bootstrap輸入框組件簡(jiǎn)單實(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)文章
20條學(xué)習(xí)javascript的編程規(guī)范的建議
本文總結(jié)了20條javascript的編程規(guī)范,都是平時(shí)項(xiàng)目中使用的時(shí)候需要注意的地方,這里推薦給大家,如對(duì)大家有所幫助,那便是極好的了。2014-11-11Save a File Using a File Save Dialog Box
Save a File Using a File Save Dialog Box...2007-06-06js實(shí)現(xiàn)for循環(huán)跳過undefined值示例
這篇文章主要介紹了js實(shí)現(xiàn)for循環(huán)跳過undefined值,結(jié)合實(shí)例形式分析了js使用for循環(huán)針對(duì)數(shù)組的遍歷、判斷、運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下2019-07-07Javascript attachEvent傳遞參數(shù)的辦法
找了半天找到的解決辦法,看介紹說(shuō)是javascript的閉包問題,導(dǎo)致得不能直接讀取外部的那個(gè)函數(shù),不然就所有傳遞的參數(shù)都變?yōu)樽詈笠粋€(gè)了。2009-12-12JS實(shí)現(xiàn)禁止高頻率連續(xù)點(diǎn)擊的方法【基于ES6語(yǔ)法】
這篇文章主要介紹了JS實(shí)現(xiàn)禁止高頻率連續(xù)點(diǎn)擊的方法,通過事件監(jiān)聽結(jié)合定時(shí)器實(shí)現(xiàn)針對(duì)高頻率點(diǎn)擊的限制操作,該功能基于ES6語(yǔ)法實(shí)現(xiàn),需要的朋友可以參考下2017-04-04身份證號(hào)碼前六位所代表的省,市,區(qū), 以及地區(qū)編碼下載
身份證號(hào)碼前六位所代表的省,市,區(qū), 以及地區(qū)編碼下載...2007-04-04javascript cookie解碼函數(shù)(兼容ff)
javascript cookie解碼函數(shù)2008-03-03詳解bootstrap的modal-remote兩種加載方式【強(qiáng)化】
本篇文章主要介紹了詳解bootstrap的modal-remote兩種加載方式【強(qiáng)化】,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01