将值设置为aria-controls输入 [英] Set value to an aria-controls input

查看:328
本文介绍了将值设置为aria-controls输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置输入aria-control值。但我无法使用传统的jQuery方式。

I want to set an input aria-control value. But I can't do it using the traditional jQuery way.

我的代码就是这个:

function showMessage() {
  var message = jQuery("#textToDisplay").val();
  $("#example").text(message);
}

<script src="https://ajax.googleapis.com/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">

如何设定价值?

推荐答案

像这样更改选择器。你的选择器目标 id 而不是咏叹调-controls 所以请使用 attr选择器。也不要输入有 text()属性所以用更改val()

Change 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.com/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">

低于 Terry 评论
使用 addeventlistener 而不是内联点击功能。这样点击功能就像这样

For below Terry comment 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.com/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">

这篇关于将值设置为aria-controls输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆