onchange same function multiple times
I have the below func开发者_如何学编程tion to use in onchange function. Can I use the same function for multiple times in the same form ?
<script type="text/javascript">
function showfield(name) {
if (name === 'Other') {
document.getElementById('div1').innerHTML = '<html:text name="reDataForm" property="member.accountNumber" styleClass="formContent" maxlength="9" size="9"/>';
} else {
document.getElementById('div1').innerHTML = '';
}
}
</script>
The answer to your question, specifically, is yes. You can - and should - reuse code functions as much as possible. That is a core concept in programming - don't repeat yourself.
With that said, another important concept is to not be afraid to experiment. Rather than asking stackoverflow if you can reuse this function, you ought to have tried it yourself. You would have answered your own question before you had ever asked it! :)
精彩评论