我想在点击更新按钮
之前更新radiobutton点击的数据百分比值HTML:
<input type="radio" name="percentage" value="50" onclick="changeVal(this.value)"> Happy 50 percent</input>
</br>
<input type="radio" name="percentage" value="75" onclick="changeVal(this.value)"> Happy 75 percent</input>
</br>
<button class="btn btn-danger my-btn" id = "myUpdateBtn" data-id="1" data-name="John" data-summary="John is Happy" data-percent="50" >Click to Update</button>
javascript:我的脚本功能不更新按钮子属性值。请帮忙。
changeVal(val){
alert(val);
document.getElementById("myUpdateBtn").value('data-price') = val;
}
答案 0 :(得分:1)
要访问data
属性,您必须这样做:
var val = document.getElementById('21').dataset.id;
var msg = document.getElementById('21').dataset.name;
alert(val); //Alert '21'
alert(msg); //Alert 'HiDiv'
document.getElementById('21').dataset.lastName = 'Rod'; //Create new data attribute
console.log(document.getElementById('21')); //View changes
&#13;
<div data-id='21' id='21' data-name = 'HiDiv'>
</div>
&#13;