我正在研究具有基本知识的svg元素。在我的网页中,我想在它们之间显示四个自定义形状的按钮图像。对于我选择svg的自定义形状,我创建了按钮并将它们放置在链接中。现在的问题是当我点击它们时,所有按钮上的文字内容都应该改变。
在函数chngText()中使用DOM我能够更改文本,直到我点击“确定”弹出警告。单击“确定”后,文本将更改为正常的先前文本。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="CSS3 Menu_files/css3menu1/style3.css" type="text/css" /><style type="text/css">._css3m{display:none}</style>
<script type="text/JavaScript" src="cordova.js"></script>
<script type="text/JavaScript" src="index.js"></script>
<script type="text/JavaScript" >
function chcT(color) {
document.getElementById('a').style.fill= color;}
function chcH(color) {
document.getElementById('b').style.fill= color;}
function chcE(color) {
document.getElementById('d').style.fill= color;}
function chcO(color) {
document.getElementById('c').style.fill= color;}
function chngText() {
document.getElementById('tel').textContent= "kakada Aarthi";
alert('x');
}
</script>
</head>
<body>
<div >
<svg width="600" height="600" viewbox="100 0 600 600">
<g id="buttons">
<defs>
<filter id="f1" x="0" y="0" width="200%" height="200%">
<feOffset result="offOut" in="SourceGraphic" dx="0" dy="0" />
<feBlend in="SourceGraphic" in2="offOut" mode="normal" />
</filter>
</defs>
<!-- path for shape -->
<a xlink:href="" onclick="chngText()" >
<path id="a" d="M200,200
C200,100 200,100 300,100 L300,150 C250,150 250,150 250,200 z" style="stroke:skyblue; stroke-width:5; fill: red; filter="url(#f1)"" />
<defs><!--path for text in shape -->
<path id="TelTxtPath"
d="M230,180
C230,130 230,130 300,130"/>
</defs>
<defs><!--path for text in shape -->
<path id="TelTxtPath1"
d="M230,180
C230,130 230,130 300,130"/>
</defs>
<text x="-4" y="30" textLength="20" style="font-size:16; font-family: arial; stroke: white; fill:black" onmouseover="chcT('springgreen')" onmouseout="chcT('red')" >
<textPath id="tel" xlink:href="#TelTxtPath" >Telugu Aarthi</textPath>
</text></a>
<a xlink:href="http://www.google.com">
<path id="b" d="M320,100
C420,100 420,100 420,200 L370,200 C370,150 370,150 320,150 z" stroke="skyblue" stroke-width="5" fill="orange" filter="url(#f1)"/>
<defs>
<path id="HindiTxtPath"
d="M330,130
C390,130 390,130 390,185"/>
</defs>
<text x="10" y="40" textLength="40" style="font-size:16; font-family: arial; stroke: black; fill:white; letter-spacing: 1" onmouseover="chcH('springgreen')" onmouseout="chcH('orange')">
<textPath xlink:href="#HindiTxtPath" >Hindi Aarthi</textPath>
</text></a>
<a xlink:href="http://www.google.com">
<path id="c" d="M420,220
C420,320 420,320 320,320 L320,270 C370,270 370,270 370,220 z" stroke="skyblue" stroke-width="5" fill="blue" filter="url(#f1)"/>
<defs>
<path id="OptionsPath"
d="M390,230
C390,290 390,290 330,290"/>
</defs>
<text x="10" y="40" textLength="40" style="font-size:16; font-family: arial; stroke: black; fill:white; letter-spacing: 4" onmouseover="chcO('springgreen')" onmouseout="chcO('blue')">
<textPath xlink:href="#OptionsPath" >Options</textPath>
</text></a>
<a xlink:href="http://www.google.com">
<path id="d" d="M300,320
C200,320 200,320 200,220 L250,220 C250,270 250,270 300,270 z" stroke="skyblue" stroke-width="5" fill="#66ff00" filter="url(#f1)"/>
<defs>
<path id="EnglishTxtPath"
d="M280,290
C230,290 230,290 230,240"/>
</defs>
<text x="-5" y="40" textLength="40" style="font-size:15; font-family: arial; stroke: white; fill:black; letter-spacing: 0" onmouseover="chcE('springgreen')" onmouseout="chcE('#66ff00')">
<textPath xlink:href="#EnglishTxtPath" >English Aarthi</textPath>
</text></a>
</g>
</svg>
</div>
<div height="600" width="600">
<img id="shape" src="C:\Users\naani\Downloads\App logo.png" />
</div>
<!-- <audio autoplay loop type="audio/mpeg" id="sai" src="C:\Users\naani\Downloads\Music\Madhyan aarti\002_Aarti Saibaba_128kbps.mp3" /> -->
</body>
</html>
css文件
@-webkit-keyframes mymove {
100% {box-shadow: 5px 3px 5px 20px yellow;}
}
svg {
position: relative;
}
svg path:hover {
fill: springgreen !important;
}
img {
position: absolute;
margin-left:270px;
margin-top:-435px;
display: block;
height: 75px ; width:75px;
-webkit -animation: mymove 5s infinite;
animation: mymove 5s infinite;
border-radius: 10%;
border-style: groove;
}
body {
background-color: springgreen;}