【发布时间】:2014-12-05 11:24:39
【问题描述】:
我在正在执行操作的 TEXT 上有一个 href。 (该操作正在更改我与另一个 div 一起使用的 div)。 我想将 TEXT 更改为 BUTTON,但我知道我不能将“按钮标签”嵌入到“标签”中。
<a href="EXTERNALPAGE.html" onmousedown="loadextPage(event) "> BACKBUTTON </a>
<button id="back_button"> BACKBUTTON </button>
另外这是事件的代码:
function loadextPage(event) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('pop_up_frame').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", event.target.href, true);
xmlhttp.send();
}
解决了
<div id="back_button" onclick="return false" onmousedown="loadextPage(event)" style="cursor:pointer">
<button>
<a href="secondpopup.html"> Go Back </a>
</button>
</div>
和
<script>
function loadextPage(event) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('pop_up_frame').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", event.target.href, true);
xmlhttp.send();
}
</script>
【问题讨论】:
-
你到底在问什么?是否可以将其设为按钮,或者为什么单击时不执行事件?
-
两者我都能理解。
-
onclick="return false"因为此链接无效,请尝试删除它 -
您对使用“onmousedown”有何想法? onclick 不是您想要的选项吗?
-
等等,你希望它是一个按钮还是不?您的代码和问题不匹配