admin管理员组文章数量:1400384
I want to set an input aria-control value. But I can't do it using the traditional jQuery way.
My code is this one:
function showMessage() {
var message = jQuery("#textToDisplay").val();
$("#example").text(message);
}
<script src=".1.1/jquery.min.js"></script>
<input type="text" id="textToDisplay" />
<input type="button" value="Add message" onClick="showMessage()" />
<input aria-controls="example" type="text">
I want to set an input aria-control value. But I can't do it using the traditional jQuery way.
My code is this one:
function showMessage() {
var message = jQuery("#textToDisplay").val();
$("#example").text(message);
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="textToDisplay" />
<input type="button" value="Add message" onClick="showMessage()" />
<input aria-controls="example" type="text">
How can I set the value?
Share Improve this question edited Aug 15, 2017 at 8:32 Terry 66.3k16 gold badges105 silver badges126 bronze badges asked Aug 15, 2017 at 8:27 Fran RodFran Rod 5864 gold badges14 silver badges26 bronze badges3 Answers
Reset to default 4Change the selector like this.your selector target the id
not the aria-controls
so use with attr selector.Also Input not have text()
property so change with val()
function showMessage() {
var message = jQuery("#textToDisplay").val();
$("input[aria-controls=example]").val(message);
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="textToDisplay" />
<input type="button" value="Add message" onClick="showMessage()" />
<input aria-controls="example" type="text">
For below Terry
ment
use addeventlistener
instead of inline click function.That do the click function in dom like this
$('#click').click(function() {
var message = jQuery("#textToDisplay").val();
$("input[aria-controls=example]").val(message);
})
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="textToDisplay" />
<input type="button" id="click" value="Add message">
<input aria-controls="example" type="text">
Use attr selector
Selects elements that have the specified attribute with a value exactly equal to a certain value.
$( "input[aria-controls='example']").val(message);
You can use
$("#myId").attr("aria-controls", myValue);
Hope this helps!
本文标签: javascriptSet value to an ariacontrols inputStack Overflow
版权声明:本文标题:javascript - Set value to an aria-controls input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744150342a2593032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论