javascript在mozilla firefox上不起作用 [英] javascript not working on mozilla firefox
本文介绍了javascript在mozilla firefox上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码,它可以在Internet Explorer中工作,但不能在mozilla firefox中工作.
I am using following code and it is working in internet explorer but not in mozilla firefox.
<style type="text/css">
.abc
{
display:block;
}
.xyz
{
display:none;
}
</style>
<script type="text/javascript" language="javascript">
function show1(id)
{
//
// var e=document.getElementById('d1');
// if(e)
// {
//
if(d1.style.display!='block')
{
d1.style.display='block';
d2.style.display='none';
d3.style.display='none';
d4.style.display='none';
}
else
{
d1.style.display='none';
}
}
//}
function show2(id)
{
if(d2.style.display!='block')
{
d2.style.display='block';
d1.style.display='none';
d3.style.display='none';
d4.style.display='none';
}
else
{
d2.style.display='none';
}
}
function show3(id)
{
if(d3.style.display!='block')
{
d3.style.display='block';
d1.style.display='none';
d2.style.display='none';
d4.style.display='none';
}
else
{
d3.style.display='none';
}
}
function show4(id)
{
if(d4.style.display!='block')
{
d4.style.display='block';
d1.style.display='none';
d3.style.display='none';
d2.style.display='none';
}
else
{
d4.style.display='none';
}
}
</script>
<body
<form id="form1" runat="server">
<div></div>
<div id='h1' class="abc" onclick="show1('d1')" >
<a href="#" style="font-size: x-large; text-decoration: none; color: #9900CC;">Customers</a>
</div>
<div id='d1' class="xyz"
<a href="Customers.aspx?action=mod" class="style5" >View Customers</a><br />
<a href="Customers.aspx?action=sav" class="style5"
>Add Customer</a>
</div><br />
<div id='h2' class="abc" onclick="show2('d2')" >
<a href="#" style="font-size: x-large; text-decoration: none; color: #9900CC;">Engineers</a>
</div>
<div id='d2' class="xyz" >
<a href="Engineer.aspx?action=mod" class="style5" >View Engineers</a><br />
<a href="Engineer.aspx?action=sav" class="style5">Add Engineer</a>
</div><br />
<div id='h3' class="abc" onclick="show3('d3')" >
<a href="#" style="font-size: x-large; text-decoration: none; color: #9900CC;">Location</a>
</div>
<div id='d3' class="xyz" >
<a href="Country.aspx" class="style5" >Country</a><br />
<a href="State.aspx" class="style5">State</a><br />
<a href="City.aspx" class="style5">City</a>
</div> <br />
<div id='h4' class="abc" onclick="show4('d4')" >
<a href="#" style="font-size: x-large; text-decoration: none; color: #9900CC;">Licence</a>
</div>
<div id='d4' class="xyz" >
<a href="License.aspx?action=mod" class="style5" >View Licences</a><br />
<a href="License.aspx?action=sav" class="style5">Add Licence</a>
</div>
</form>
</body>
推荐答案
使用document.getElementById获取d1,d2,d3,d4.
您使用了4个功能,但全部退出相同.这也是不好的做法.
试试这样的事情
Use document.getElementById for get d1,d2,d3,d4.
You used 4 functions but all are quit same. It is also bad practice.
Try some thing like this
function show1(id)
{
if(document.getElementById(id).style.display!=''block'')
{
document.getElementById("d1").style.display=''none'';
document.getElementById("d2").style.display=''none'';
document.getElementById("d3").style.display=''none'';
document.getElementById("d4").style.display=''none'';
document.getElementById(id).style.display=''block'';
}
else
{
document.getElementById(id).style.display=''none'';
}
}
我有一个示例,请尝试理解它并在您的代码中使用它
这仅用于验证数字,即在您按下键时仅接收数字
Hi,
I have a example pls try to understand it and use it in your code
this is for validating only numbers ie it takes only numbers when you press the keys
function browsercompatbility() {
if (browserName == "Netscape") {
document.onkeydown = keyDown;
document.captureEvents(Event.KEYDOWN);
eventkey = keycode;
}
else {
key = parseInt(event.keyCode);
eventkey = key;
}
}
function validatenumbers() {
browsercompatbility();
if ((parseInt(eventkey) >= 47) && (parseInt(eventkey) <= 57)) {
return true;
}
else { eventkey = 0; return false; }
return true;
}
这篇关于javascript在mozilla firefox上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文