隐藏/显示在ie8中不工作
Hide/Show is not working in IE 8
我有两个下拉列表。基于第一个下拉值,隐藏第二个下拉值。但是hide()和show()在IE 8中不起作用。但在Firefox中运行良好。
代码:<script type="text/javascript">
function marketcd_dropdown_const(){
alert($("#first").val());
switch ($("#first").val())
{
case 'ONE':
$('.market_code_dropdown').hide();
$('.instorder').hide();
$('#all_option').prop('selected',true);
break;
case 'TWO':
$('.market_code_dropdown').hide();
$('.instorder').hide();
$('#all_option').prop('selected',true);
break;
default:
$('.market_code_dropdown').show();
$('.instorder').show();
$('#all_option').prop('selected',true);
break;
}
}
$(document).ready(function(){
alert("ready function");
$(document).bind('change', ".first_class", marketcd_dropdown_const);
});
</script>
JSP: <SELECT NAME=BillingSystem id="first" class="first_class" size="1" onchange="nuvoxcolumn(this);" >
<!-- // Option All -->
<option value=<%= m_strALL %>
<%
if (m_bGet || m_strOldBillingSystem.equals("%"))
{%>
<%= m_selected %>
<%}
%>
>
<%= m_strAllSearch %>
<%Log.write("m_strAllSearch for billing system: "+m_strAllSearch); %>
</option>
<%
while(m_strBillSystemList[iCount] != null)
{
String strBillSystem = m_strBillSystemList[iCount];
%>
<OPTION VALUE=<%= strBillSystem %>
<%Log.write("m_strOldBillingSystem: "+m_strOldBillingSystem); %>
<%
if (m_strOldBillingSystem != null)
{
if (m_strOldBillingSystem.equals(strBillSystem))
{%>
<%= m_selected %>
<%}
}
%> >
<%= strBillSystem %>
<%Log.write("strBillSystem: "+strBillSystem); %>
</option>
<%
iCount++;
}
%>
</select>
<SELECT NAME=MarketCode id="second" size = 1>
<!-- // Option All -->
<option id="all_option" value=<%= m_strALL %>
<%
if (m_bGet || m_strOldMarketCode.equals("%"))
{%>
<%= m_selected %>
<%}
%> >
<%= m_strAllSearch %>
<%Log.write("m_strAllSearch for market code: "+m_strAllSearch); %>
</option>
<%
while(m_strMktCodeList[iCount] != null)
{
String strMktCode = m_strMktCodeList[iCount];
%>
<OPTION class="market_code_dropdown" VALUE=<%= strMktCode %>
<%
if (m_strOldMarketCode != null)
{
if (m_strOldMarketCode.equals(strMktCode))
{%>
<%= m_selected %>
<%}
}
%> >
<%= strMktCode %>
<%Log.write("strMktCode: "+strMktCode); %>
</option>
<%
iCount++;
}
%>
</select>
使用的Jquery版本:Jquery v1.4.2最后,我使用了最新的jquery版本。
我认为你需要根据最新的jQuery版本改变你的代码…
$(document).ready(function(){
alert("ready function");
$(document).on('change', ".first_class", marketcd_dropdown_const);
});
或者你可以使用jQuery迁移插件来支持旧版本代码
我运行这段代码,它正在工作…请检查一下……
<script type="text/javascript">
function marketcd_dropdown_const(){
alert($("#first").val());
switch ($("#first").val())
{
case 'ONE':
$('.market_code_dropdown').hide();
// $('.instorder').hide();
// $('#all_option').prop('selected',true);
break;
case 'TWO':
$('.market_code_dropdown').hide();
// $('.instorder').hide();
// $('#all_option').prop('selected',true);
break;
default:
$('.market_code_dropdown').show();
// $('.instorder').show();
// $('#all_option').prop('selected',true);
break;
}
}
$(document).ready(function(){
alert("ready function");
$(document).bind('change', ".first_class", marketcd_dropdown_const);
});
</script>
<body>
<SELECT NAME=BillingSystem id="first" class="first_class" size="1" >
<!-- // Option All -->
<option value="" >Select</option>
<option value="ONE" >test</option>
<OPTION VALUE='TWO'>test1 </option>
</select>
<SELECT NAME="MarketCode" id="second" size = "1" class="market_code_dropdown">
<option value="" >test</option>
<OPTION VALUE='tt'>test1 </option>
</select>
</body>
使用这个javascript版本…
<script type="text/javascript">
function marketcd_dropdown_const(obj){
switch (obj.value)
{
case 'ONE':
document.getElementById('second').style.display = 'none';
// $('.instorder').hide();
// $('#all_option').prop('selected',true);
break;
case 'TWO':
document.getElementById('second').style.display = 'none';
// $('.instorder').hide();
// $('#all_option').prop('selected',true);
break;
default:
document.getElementById('second').style.display = 'block';
// $('.instorder').show();
// $('#all_option').prop('selected',true);
break;
}
}
</script>
<body>
<SELECT NAME=BillingSystem id="first" class="first_class" size="1" onChange=" marketcd_dropdown_const(this)" >
<!-- // Option All -->
<option value="" >Select</option>
<option value="ONE" >test</option>
<OPTION VALUE='TWO'>test1 </option>
</select>
<SELECT NAME="MarketCode" id="second" size = "1" class="market_code_dropdown">
<option value="" >test</option>
<OPTION VALUE='tt'>test1 </option>
</select>
</body>
你的JQuery版本不是最新的,这是我认为主要的问题。
可能有一个解决问题的方法,但老实说,试图让旧版本工作只是一个持续的头痛。
这是我的解决方案,将适用于你
在css中创建一个新类:
.hideme { display: none; }
现在,而不是
$('.market_code_dropdown').hide();
$('.market_code_dropdown').show();
使用$('.market_code_dropdown').addClass('hideme');
$('.market_code_dropdown').removeClass('hideme');
从v.1.4开始支持以下函数
相关文章:
- IE8更改文本区域上的事件侦听器不工作
- window.onbeforeunload在IE8中不触发(在Firefox,Chrome和Safari中工作正常)
- $('body').on('blur')在IE8中工作不好
- window.location重定向没有'我不在IE8上工作
- addEventListener没有'不能在IE中工作(在IE8中测试)
- Requirejs和主干应用程序,不能在IE8中工作
- 无法在 IE 9 中传递此运算符的值,而它在 IE7 和 IE8 中工作正常
- Request.UrlReferrer在IE8中无法正常工作,并且工作正常IE9
- 不触发 OnClick 事件 IE8,但在 Firefox 中工作正常
- 如何优化我的jQuery以始终在IE8中工作,目前它被击中和错过
- 获取尾随逗号(在JavaScript中)在IE7 / IE8中工作
- FormData ajax 上传 IE8 -> 替代品及其工作原理
- jquery设置隐藏的输入值在IE7和IE8中未按预期工作
- 在 IE8 中单选按钮上更改无法正常工作
- 如何让 jQuery methos text() 函数在 IE8 中工作
- 重写一个Javascript函数,该函数可以选择在IE8中工作的活动导航选项卡
- 修复了在页面底部加载时html5标签IE8不工作的问题
- js库无法在IE8中工作
- 输入类型=“file".submit()不工作IE8
- 让cufon在IE7中工作IE8 -我已经按照文档做了所有的事情