0

因此,我只希望在响应中出现两次的名称以斜体显示。我是一个真正的菜鸟,所以请帮助我并清楚。我很感激 http://dave-reed.com/book3e/Ch5/greet.html 这是示例网站。我希望您的名字仅在响应中用斜体字显示。

<!DOCTYPE html>
<!-- saved from url=(0042)http://dave-reed.com/book3e/Ch5/greet.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title> Greetings </title>
 </head>

 <body>
   <h2>Greetings</h2>
   <p>
     Enter your name: <input type="text" id="nameBox" size="12" value="">
   </p>
   <input type="button" value="Click for Greeting" onclick="document.getElementById('outputDiv').innerHTML=
                     'Hello ' + document.getElementById('nameBox').value + 
                     ', welcome to my page.<br>Do you mind if I call you ' +
                     document.getElementById('nameBox').value + '?';"> 
   <hr>
   <div id="outputDiv"></div>

</body></html>
4

2 回答 2

0
<!DOCTYPE html>
<!-- saved from url=(0042)http://dave-reed.com/book3e/Ch5/greet.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title> Greetings </title>
<style type="text/css">
.italic {
    font-style:italic;
}
</style>
 </head>

 <body>   
<h2>Greetings</h2>
   <p>
     Enter your name: <input type="text" id="nameBox" size="12" value="">
   </p>
   <input type="button" value="Click for Greeting" onclick="document.getElementById('outputDiv').innerHTML=
                     'Hello <span class=\'italic\'>' + document.getElementById('nameBox').value + 
                     '</span>, welcome to my page.<br>Do you mind if I call you <span class=\'italic\'>' +
                     document.getElementById('nameBox').value + '</span>?';"> 
   <hr>
   <div id="outputDiv"></div>
</body></html>
于 2014-01-26T04:40:24.047 回答
0

创建一个新的 CSS 规则:

.test{
    font-style: italic;
}

然后<span class=\'test\'> </span>在名称的每个实例周围添加,像这样......

 <body>
   <h2>Greetings</h2>
   <p>
     Enter your name: <input type="text" id="nameBox" size="12" value="">
   </p>
   <input type="button" value="Click for Greeting" onclick="document.getElementById('outputDiv').innerHTML=
                     'Hello <span class=\'test\'>' + document.getElementById('nameBox').value + 
                     '</span>, welcome to my page.<br>Do you mind if I call you <span class=\'test\'>' +
                     document.getElementById('nameBox').value + '</span>?';"> 
   <hr>
   <div id="outputDiv"></div>

</body>

在这里查看小提琴

于 2014-01-26T04:42:56.607 回答