我有两个功能一个是
var tag = document.getElementById('tag');
map.onchange = function() {
tag.innerHTML = maps[this.value][1];
}
,另一个是
var tag2 = document.getElementById('tag2');
map.onchange = function() {
tag2.innerHTML = maps[this.value][2];
}
我也有两个链接
<a href="#" >iframe option one</div></a> | <a href="#">iframe option two</a>
我希望标准文本自动成为第一个函数。 然后当我点击第二个链接时。它将关闭第一个功能和第二个功能。我知道最近会发生什么。我只是不确定如何恭维它。我不想用JQuery做这件事。非常感谢你
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
window.onload=function(){
var maps = new Array();
maps[0] = ["Text A1", "Text A2", "Text A3"];
maps[1] = ["Text B1", "Text B2", "Text B3"];
maps[2] = ["Text C1", "Text C2", "Text C3"];
maps[3] = ["Text D1", "Text D2", "Text D3"];
maps[4] = ["Text E1", "Text E2", "Text E3"];
maps[5] = ["Text F1", "Text F2", "Text F3"];
var map = document.getElementById("complaintType");
for (i = 0; i < maps.length; i++) {
var Entry = document.createElement("option");
Entry.text = maps[i][0];
Entry.value = i;
map.add(Entry, null);
}
var tag = document.getElementById('tag');
map.onchange = function() {
tag.innerHTML = maps[this.value][1];
tag.innerHTML = maps[this.value][2];
}
}
</script>
</head>
<body>
<form>
<select name="complaintType" id="complaintType">
<option value="">Select One</option>
</select>
</form>
<a href="#">Option 1</a> | <a href="#">Option 2</a>
<div id="tag"></div>
</body>
</html>
答案 0 :(得分:0)
为两个链接指定ID:
<a href="#" id="iframe1">iframe option one</a> | <a href="#" id="iframe2">iframe option two</a>
在函数中使用map.onchange的两个链接添加一个clickevent:
var iframe1 = document.getElementById("iframe1");
var iframe2 = document.getElementById("iframe2");
iframe1.onclick = function () {
var tag = document.getElementById('tag');
map.onchange = function () {
tag.innerHTML = maps[this.value][1];
}
}
iframe2.onclick = function () {
var tag2 = document.getElementById('tag2');
map.onchange = function () {
tag2.innerHTML = maps[this.value][2];
}
}
添加结束,第一次加载:
var tag = document.getElementById('tag');
map.onchange = function () {
tag.innerHTML = maps[this.value][1];
}