Jquery Doesn't function
Jquery Doesn't function
我已经写了这个原因来用jQuery显示和隐藏select组件,但它不起作用,你能告诉我问题在哪里吗?
<html>
<head>
<meta charset='UTF-8' />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Exo:100,200,400">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:700,400,300">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
这是要显示的CSS部分。隐藏
<style type="text/css">
.hide {
display: none;
}
</style>
jQuery代码
<script>
$(document).ready(function () {
function changeType() {
if ($("#typeservice").val() == "voice") {
$("#country").show();
$("#sgnl").show();
$("#Operator").hide();
$("#tech").hide();
}
if ($("#typeservice").val() == "data") {
$("#country").show();
$("#sgnl").hide();
$("#Operator").show();
$("#tech").hide();
}
if ($("#typeservice").val() == "Radio") {
$("#country").show();
$("#sgnl").hide();
$("#Operator").hide();
$("#tech").show();
}
}
});
</script>
</head>
<body>
<select id="typeservice" style="width: 100px" onchange="changeType();">
</select>
<select id="sgnl" style="width: 100px; ">
</select>
<select id="country" style="width: 100px;">
</select>
</body>
</html>
但所有选择的组件都出现了,没有显示或动态显示!
在文档就绪功能中,隐藏除typeservice下拉列表之外的所有选择组件。请尝试使用以下代码隐藏文档中的组件。
$(document).ready(function(){
$("#country").hide();
$("#sgnl").hide();
$("#Operator").hide();
$("#tech").hide();
});
这个问题在这里已经有了一个公认的答案,这只是另一种方法。
我们可以使用jquery 绑定选择下拉列表的onchange
事件
注意:最好使用if-else而不是if-ehere
javascript
$(document).ready(function(){
$(document.body).on('change','#typeservice',function(){
if ($("#typeservice").val()=="voice") {
$("#country").show();
$("#sgnl").show();
$("#Operator").hide();
$("#tech").hide();
}
else if ($("#typeservice").val()=="data") {
$("#country").show();
$("#sgnl").hide();
$("#Operator").show();
$("#tech").hide();
}
else if ($("#typeservice").val()=="Radio") {
$("#country").show();
$("#sgnl").hide();
$("#Operator").hide();
$("#tech").show();
}
});
});
html
<select id="typeservice" style="width: 100px">
</select>
<select id="sgnl" style="width: 100px; ">
</select>
<select id="country" style="width: 100px;">
</select>
相关文章:
- 直接在函数声明上使用function.prototype.bind
- jQuery:.click(function(){(element),collapse('show',f
- 如果连接类型为none,则Javascript Function Only警报
- onLoad function phonegap android
- reducers在redux中得到Function not Object,what'it’他错了
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- $(document).ready和jQuery(function($)不工作;jQuery已定义,但脚本尚未定义;t进
- Javascript onunload function
- 在init function()中调用getElementById(“..”),而不是想用它做点什么的函数
- spyOn:应为间谍,但得到了Function
- (typeof variable === “function”) 和 jQuery.isFunction() 有什么区别
- this内部的值返回this.each(function(){})
- 如何在JavaScript中创建类似于something.function()的函数
- 如何通过 Function.prototype.apply() 更改调用函数的参数
- 控制台中的“function floor(){[本机代码]}”是什么
- ASPX Jquery 1.11 $(Document).ready(function() {} was skipped
- Function.prototype.call和Function.protoype.all只应用一个参数
- Jquery Doesn't function
- JavaScript: $(document).ready(function () { doesn't acti
- selenium sendkeys doesn't function