<!--这个程序使用了javascript中的this,this可以减少很多不必要的代码量,并且提高代码的效率-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function processData(form){
for (var i = 0; i < form.Beatles.length; i++) {
if (form.Beatles[i].checked) {
break;
}
}
var beatle = form.Beatles[i].value;
var song = form.song.value;
alert("Checking whether"+" "+ song+" "+ "features"+" "+ beatle+" "+ "...");
}
function verifySong(entry){//这里的entry是随便起的也可以叫别的名
var song = entry.value;
alert("Checking whether" +" "+ song+" " + "is a Beatles tune...");
}
</script>
</head>
<body>
<form onSubmit="return false">
Choose your favorite Beatle:
<input type="radio" name="Beatles" value="John Lennon" checked/>John <!--看到这里的checked了吧可以这样太简单了-->
<input type="radio" name="Beatles" value="Paul McCartney"/>Paul
<input type="radio" name="Beatles" value="George Harrison"/>George
<input type="radio" name="Beatles" value="Ringo Starr"/>Ringo
<p>
Enter the name of your favorite Beatles song:
<br>
<input type="text" name="song" value="Eleanor Rigby" onChange="verifySong(this)"/>
<p>
<input type="button" name="process" value="Process Request..." onClick="processData(this.form)"/>
<!--因为这个按钮是要提交表单的,直接将form传到指定的函数中-->
</form>
</body>
</html>
分享到:
相关推荐
NULL 博文链接:https://wv1124.iteye.com/blog/505231
JavaScript中this的指向还没搞明白?来这看看 你就懂啦~
在全局作用域中使用 this 会返回全局对象,在浏览器环境下是 window 对象, 在 Node.js 环境下是 global 对象。例如: console.log(this === window); true function test() { console.log(this === window); } ...
Javascript 中 this指向
JavaScript程序设计javascript中this的指向问题共6页.pdf.zip
this指触发事件的对象,接下来为大家分享下javascript中onclick(this)的用法,感兴趣的朋友可以参考下哈,希望对你有所帮助
JavaScript中this指向.pdf
JavaScript中this指向.docx
详解Javascript 中的this指针
高手详解javascript中的this指针
复习JavaScript中this指向及绑定
Javascript的this用法
探寻JavaScript中this指针指向_.docx
详解JavaScript中this关键字的用法_.docx
深化理解Javascript中this的作用域_.docx
JavaScript 中的this 总是让人迷惑,应该是js 众所周知的坑之一。 个人也觉得js 中的this 不是一个好的设计,由于this 晚绑定的特性,它可以是全局对象, 当前对象,或者…有人甚至因为坑大而不用this。 其实如果...
JavaScript中的this指向.md
详解Javascript 中的this指针
详解javascript中的this对象.docx