gpt4 book ai didi

javascript - jquery 因下拉菜单选择操作而失败

转载 作者:行者123 更新时间:2023-11-30 10:22:45 25 4
gpt4 key购买 nike

我正在对下拉菜单项选择执行操作。

JS fiddle

但是当我在本地主机上测试时没有做任何操作,甚至不显示菜单项。虽然我已经包含了所有文件。

代码:

<html lang="en">
<head>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="sticky-footer-navbar.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.js"></script>

<script>
$(".dropdown-menu li a").click(function(){
alert("hi");
var selText = $(this).text();
$('label').css('color',selText);
});

</script>
</head>
<body>
<label>Test color</label>
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn btn-default">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span>

</button>
<ul class="dropdown-menu pull-right">
<li><a href="#">yellow</a>

</li>
<li><a href="#">green</a>

</li>
<li><a href="#">black</a>

</li>
<li class="divider"></li>
<li><a href="#">red</a>

</li>
</ul>
</div>
<!-- /btn-group -->
</div>
<!-- /input-group -->
</div>
</body>
</html>

这段代码有什么问题?

更新1

    <script>
$( document ).ready(function() {
alert("hi");
var selText = $(this).text();
$('label').css('color',selText);
});
</script>

没有变化

结果是这样的:

image

更新代码:

<!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.0">
<meta name="description" content="">
<meta name="author" content="">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src=" http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.js"></script>
<link href="css/bootstrapa.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<label>Test color</label>
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn btn-default">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span>

</button>
<ul class="dropdown-menu pull-right">
<li><a href="#">yellow</a>

</li>
<li><a href="#">green</a>

</li>
<li><a href="#">black</a>

</li>
<li class="divider"></li>
<li><a href="#">red</a>

</li>
</ul>
</div>
<!-- /btn-group -->
</div>
<!-- /input-group -->
</div>
<script>
$( document ).ready(function() {
alert("hi");
var selText = $(this).text();
$('label').css('color',selText);
});
</script>
</body>

</html>

最佳答案

这是您的代码:

<!doctype html>
<html lang="en">
<head>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<label>Test color</label>
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn btn-default">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span>

</button>
<ul class="dropdown-menu pull-right">
<li><a href="#">yellow</a>

</li>
<li><a href="#">green</a>

</li>
<li><a href="#">black</a>

</li>
<li class="divider"></li>
<li><a href="#">red</a>

</li>
</ul>
</div>
<!-- /btn-group -->
</div>
<!-- /input-group -->
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>


<script>
$(".dropdown-menu li a").click(function(){
alert("hi");
var selText = $(this).text();
$('label').css('color',selText);
});
</script>
</body>
</html>

希望这对您有所帮助。

关于javascript - jquery 因下拉菜单选择操作而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20889097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com