<input type="text" name="araButon" onKeyUp="return arama()" class="form-control filter" data-filter="app" id="focusedInput"/>
我想通过javascript更新'data-filter'值 我试过这段代码:
var gelenText = document.getElementById(“focusedInput”); 的document.getElementById( “focusedInput”)的getAttribute( “数据过滤器”)= gelenText.value;
有人能帮我吗?
答案 0 :(得分:2)
您可以使用dataset
或setAttribute
,
// dataset
document.getElementById('focusedInput').dataset.filter = "test";
// setAttribute
document.getElementById('focusedInput').setAttribute('data-filter', 'test-1');
<input type="text" name="araButon" onKeyUp="return arama()" class="form-control filter" data-filter="app" id="focusedInput" />
答案 1 :(得分:0)
这是你想要做的事情:
var focusedInput = document.getElementById("focusedInput");
var dataFilter = focusedInput.getAttribute("data-filter");
focusedInput.value = dataFilter;