如何根据javascript中按钮的数据id属性在警报中显示特定消息



当用户单击下载按钮时,我想显示一条特定的消息,但值取决于数据id。

这就是我目前所拥有的:

<div>
<ul>
<li className="col rats"><a title="Rats" href="#rats" data-id="rats" id="ratsDownload">
<li className="col frogss"><a title="Frogs" href="#frogs" data-id="frogs" id="frogsDownload">
</div>
<button type="button" onclick="show()">Download!</button>
<script>
function show(){
var idOne = document.getElementById('ratsDownload');
var idTwo = document.getElementById('frogsDownload');
var Val = rats.getAttribute('data-id');
var Val2 = frogs.getAttribute('data-id');

if(Val==rats){
alert("5");
}
if(Val2==frogs){
alert("9");
}
}
</script>
<div>
<ul>
<li className="col rats"><a title="Rats" href="#rats" data-id="rats" id="ratsDownload">
<li className="col frogss"><a title="Frogs" href="#frogs" data-id="frogs" id="frogsDownload">
</div>
<button type="button" onclick="show()">Download!</button>
<script>
function show(){
var idOne = document.getElementById('ratsDownload');
var idTwo = document.getElementById('frogsDownload');
var Val = idOne.getAttribute('data-id');
var Val2 = idTwo.getAttribute('data-id');

if(Val==="rats"){
alert("5");
}
if(Val2==="frogs"){
alert("9");
}
}
</script>

相关内容

  • 没有找到相关文章

最新更新