实习十javascrip沤t的使用四.pptVIP

  • 1
  • 0
  • 约5.09千字
  • 约 24页
  • 2018-12-25 发布于福建
  • 举报
实习十javascrip沤t的使用四

实习十 Javascript的使用(四) 实验要求 1. Javascript综合应用 2.全面掌握Javascript编程 实验内容 4. 综合练习 4..1 使用复选框 [例4.20]使用复选框。 html head script language=″JavaScript″ function c1(form,callingField){ if (callingField==″result″){ if (form.square.checked){ form.entry.value=Math.sqrt(form.result.value) } else{ form.entry.value= form.result.value/2; } } else{ if(form.square.checked) { form.result.value= form.entry.value*form.entry.value }else{ form.result.value= form.entry.value*2 } } } /script /head body form method=post 请输入一个值:br input type=″text″ name=″entry″ value=″0″ onChange=″c1(this.form, this.name)″; p 选择计算平方否则计算加倍: input type=checkbox name=square onChange=″c1(this.form, this.name)″; p 结果为: input type=″text″ name=″result″ value=″0″ onChange=″c1(this.form, this.name)″; /form /body /html 在浏览器中可以看到如图4.20所示的页面。 注意: 如果输入的不是数字将返回NaN。 4..2 使用单选框 用单选框实现加倍与平方。 html head script language=″JavaScript″ function c1(form,callingField){ if (callingField==″result″){ if (form.action\[1\].checked){ form.entry.value=Math.sqrt(form.result.value) } else{ form.entry.value= form.result.value/2; } } else{ if(form. action\[1\].checked) { form.result.value= form.entry.value*form. entry.value }else{ form.result.value= form.entry.value*2 } } } /script /head body form method=post 请输入一个值:br input type=″text″ name=″entry″ value=0 onChange=″c1(this.form, this.name)″;p 选择加倍: input type=″radio″ name=″action″ value=″加倍″ onClick=″c1(this.form, this.name)″;p 选择平方: input type=″radio″ name=″action″ value=″平方″ onClick=″c1(this.form, this.name)″;p 结果为: input type=″text″ name=″result″ value=″0″ onChange=″c1(this.form, this.name)″; /form /body /html 在浏览器中你可以看到如图4.21所示的页面。 注意: 如果输入的不是数字将返回NaN。 nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; 圆面积为:nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; input type=″text″ name=″results1″ onFocus=″this.blur( );″ /fontpfont size=″3″ nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; input type=″button″ value=″计算阶乘″ onClick=″c3(this.form);″ nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp; nbsp;nb

文档评论(0)

1亿VIP精品文档

相关文档