【问题标题】:Change text into <span> with jquery comand使用 jquery 命令将文本更改为 <span>
【发布时间】:2016-11-28 22:55:42
【问题描述】:

我需要将文本更改为跨度。

我正在寻找这个,因为我有一个下拉菜单,我使用 jQuery 选择器选项,但这不会更改文本,只能从选项中选择。

我需要用其他文本更改“seleziona”。

【问题讨论】:

  • 请不要发布您的代码图片,请发布 ("minimal reproducible example") 代码本身。另外,你用过什么“jQuery 选择器选项”?你在哪里卡住了?你的尝试出了什么问题?你期望代码做什么,它做了什么?
  • 我用这个:var theText = ""; $("# option").each(function() { if($(this).text() == theText) { $(this).attr('selected', 'selected'); } });

标签: jquery class drop-down-menu selector


【解决方案1】:
  1. 您可以进行更改事件
  2. 然后触发它

1.

$("#span1").on('change',function(){
 //Do calculation and change value of other span here
 $("#span2").text('calculated value');});

2.

$("#span1").text('test').trigger('change'); 

【讨论】:

    【解决方案2】:

    Srebnywilkun 发布的答案是正确的。这个答案只提供了一个简短的符号。

    $("#span1").on('change',function(){
        $("#span2").text('calculated value');
    }).change(); // defining this at the end of the function would automatically trigger the change event after the event is registered.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多