开发者

java script: onblur() working in opera but not in mozilla

开发者 https://www.devze.com 2023-01-29 07:34 出处:网络
开发者_StackOverflow社区This is my code : <script> function showVehical(type){ var element = document.getElementById(\'TotalCoach\');

开发者_StackOverflow社区This is my code :

<script>
function showVehical(type){
var element = document.getElementById('TotalCoach');
element.onblur="myfunction(type);";
}

function myfunction(type){
alert(type);
}

</script>

<HTML>
<body>
<input type="text" name="totalNumberOfCoach" id="TotalCoach" value="1"/>
</body>
</HTML>

The above code is working fine on opera but not in mozilla onblur() not working.


Try using a javascript library (like jQuery), to eliminate discrepancies between browsers.


Where do you call showVehical()? It needs to be after the TotalCoach input field is ready. This code works for me:

<script>
function showVehical(type){
var element = document.getElementById('TotalCoach');
element.onblur=function() {myfunction(type);};
}

function myfunction(type){
alert(type);
}
</script>
<HTML>
<body>
<input type="text" name="totalNumberOfCoach" id="TotalCoach" value="1"/>
<script>
showVehical("a");
</script>
</body>
</HTML>
0

精彩评论

暂无评论...
验证码 换一张
取 消