JavaScript swap问题,求大神指点,重谢! 150
编写一个functionswap(tag1,tag2),将两个字符串作为参数。tag1和tag2都是HTML里id的元素,这个function应该交换这两个元素的inne...
编写一个function swap(tag1,tag2),将两个字符串作为参数。tag1和tag2都是HTML里id的元素,这个function应该交换这两个元素的innerHTML值。如果HTML不存在要的元素,弹出警告框。
编写一个函数clearit()添加一个新按钮“打印”元素id =“按钮”。这个打印按钮应该显示打印,应该有一个onclick属性,是指一个函数printit()。
编写一个function printit()显示一个警告写着文本“print called”去证明代码正常工作。
求大神指点,在线等!
<html>
<head>
<script src="q1.js"type="text/javascript"> </script>
</head>
<body>
Dear <spanid="salutation">Name</span>;
<p>
It has come to our attention that your invoice<span id="invoice">ID</span>
has yet to be paid. It has now been <spanid="time">some time</span> since
you received <span id="item">thematerial</span> from Evil Incorporated. Please
remit payment immediately. <spanid="threaten"></span>
</p>
Yours sincerely,<br>
<br>
<br>
J. Smith, Accounting
<div id="buttons">
<center>
<buttononclick="format()">Format</button>
<buttononclick="clearit()">Clear</button>
</center>
</div>
</body>
</html> 展开
编写一个函数clearit()添加一个新按钮“打印”元素id =“按钮”。这个打印按钮应该显示打印,应该有一个onclick属性,是指一个函数printit()。
编写一个function printit()显示一个警告写着文本“print called”去证明代码正常工作。
求大神指点,在线等!
<html>
<head>
<script src="q1.js"type="text/javascript"> </script>
</head>
<body>
Dear <spanid="salutation">Name</span>;
<p>
It has come to our attention that your invoice<span id="invoice">ID</span>
has yet to be paid. It has now been <spanid="time">some time</span> since
you received <span id="item">thematerial</span> from Evil Incorporated. Please
remit payment immediately. <spanid="threaten"></span>
</p>
Yours sincerely,<br>
<br>
<br>
J. Smith, Accounting
<div id="buttons">
<center>
<buttononclick="format()">Format</button>
<buttononclick="clearit()">Clear</button>
</center>
</div>
</body>
</html> 展开
1个回答
展开全部
function swap(firstId,secondId){
var firstEl = document.getElementById(firstId);
var secondEl = document.getElementById(secondId);
var temp = firstEl.innerHTML;
firstEl.innerHTML = secondEl.innerHTML;
secondEl.innerHTML = temp;
}
function clearit(){
var printBtn = document.createElement('input');
printBtn.id = 'printBtn';
printBtn.type = 'button';
printBtn.value = 'print';
printBtn.onclick = printit;
document.body.appendChild(printBtn);
}
function printit(){
alert('print called');
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询