html的调用js的调用问题。
html部分(cardtest.html)如下:<html><head><title>JavascriptBusinessCards</title></head><bod...
html部分(cardtest.html)如下:
<html>
<head>
<title>Javascript Business Cards</title>
</head>
<body>
<h1>Javascript Business Cards</h1>
<p>Script begins here.</p><hr>
<script language="javascript" type="text/JavaScript" src="../cardtext.js">
</script>
<p>End of script.</p>
</body>
</html>
cardtest.js:
function Card(name,address,work,home){
this.name=name;
this.address=address;
this.workphone=work;
this.homephone=home;}
function PrintCard(){
line1="<b>Name: </b>" + this.name+"<br>\n";
line2="<b>Address: </b>" + this.addres+"<br>\n";
line3="<b>Workphone: </b>" + this.workphone+"<br>\n";
line4="<b>Home: </b>" + this.homephone+"<br>\n";
document.write(line1,line2,line3,line4);}
sue=new Card("Sue Suthers","123 steet","65536", "6493304");
jack=new Card("Jack sheable","765 street","76253","6422906");
henry=new Card("Henry Tillman","233 Elm Street","64788","6414620");
sue.PrintCard();
jack.PrintCard();
henry.PrintCard();
但是执行的时候却没有执行js的内容? 展开
<html>
<head>
<title>Javascript Business Cards</title>
</head>
<body>
<h1>Javascript Business Cards</h1>
<p>Script begins here.</p><hr>
<script language="javascript" type="text/JavaScript" src="../cardtext.js">
</script>
<p>End of script.</p>
</body>
</html>
cardtest.js:
function Card(name,address,work,home){
this.name=name;
this.address=address;
this.workphone=work;
this.homephone=home;}
function PrintCard(){
line1="<b>Name: </b>" + this.name+"<br>\n";
line2="<b>Address: </b>" + this.addres+"<br>\n";
line3="<b>Workphone: </b>" + this.workphone+"<br>\n";
line4="<b>Home: </b>" + this.homephone+"<br>\n";
document.write(line1,line2,line3,line4);}
sue=new Card("Sue Suthers","123 steet","65536", "6493304");
jack=new Card("Jack sheable","765 street","76253","6422906");
henry=new Card("Henry Tillman","233 Elm Street","64788","6414620");
sue.PrintCard();
jack.PrintCard();
henry.PrintCard();
但是执行的时候却没有执行js的内容? 展开
2个回答
展开全部
你的js都没有触发语句,怎么会有执行呢
比如说可以写上 onload='playJs()'
然后你把
sue=new Card("Sue Suthers","123 steet","65536", "6493304");
jack=new Card("Jack sheable","765 street","76253","6422906");
henry=new Card("Henry Tillman","233 Elm Street","64788","6414620");
sue.PrintCard();
jack.PrintCard();
henry.PrintCard();
封装起来做为 playJs()
这样应该可以了吧
你body里面的调用不过是告诉电脑我将可能使用./cardtext.js这个文件,而不是让这个文件自动运行
比如说可以写上 onload='playJs()'
然后你把
sue=new Card("Sue Suthers","123 steet","65536", "6493304");
jack=new Card("Jack sheable","765 street","76253","6422906");
henry=new Card("Henry Tillman","233 Elm Street","64788","6414620");
sue.PrintCard();
jack.PrintCard();
henry.PrintCard();
封装起来做为 playJs()
这样应该可以了吧
你body里面的调用不过是告诉电脑我将可能使用./cardtext.js这个文件,而不是让这个文件自动运行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询