更改asp标签的文本

[英]changing the text of asp label


I am trying to change the text of label using jquery

我试图使用jquery更改标签的文本

function openMe(p_whoIs) {
          var $img = $(p_whoIs.alt).clone();
          $("#Label1").text($img);
          $("#dialog").dialog("open");
      }

now when i give the any value in text of label it change the value like

现在,当我给出标签文本中的任何值时,它会更改值

$("#Label1").text("img");

and var $img is also working fine i have checked it with other control but when i assign this value to label text it display [object object] not the variable $img value. So how to do that??

和var $ img工作正常我已经用其他控件检查了它但是当我将这个值赋给标签文本时它显示[object object]而不是变量$ img value。那怎么办?

3 个解决方案

#1


2  

That is because $img is a jQuery object, not string. You need to extract some string value out of this object, like src or id or..

那是因为$ img是一个jQuery对象,而不是字符串。你需要从这个对象中提取一些字符串值,比如src或id或..

It seems you are trying to extract the alt property:

看来你正试图提取alt属性:

var altText = $(p_whoIs).attr("alt");
$("#Label1").text(altText );

#2


0  

You need to pull the text from a property of $img, whatever that variable is. If it is an HTML input, then in jQuery, you would use:

您需要从$ img的属性中提取文本,无论该变量是什么。如果是HTML输入,那么在jQuery中,您将使用:

$img.val()

so that your code from above would be:

这样你上面的代码就是:

function openMe(p_whoIs) {
      var $img = $(p_whoIs.alt).clone();
      $("#Label1").text($img.val());
      $("#dialog").dialog("open");
  }

This is as close as I can get without knowing what the $img object is.

这很接近我不知道$ img对象是什么。

#3


0  

Put asp label control in div tag then use following code

将asp标签控件放在div标签中,然后使用以下代码

$("#DivID span").html($img.val());

$(“#DivID span”)。html($ img.val());


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/12/06/937162bf3d8ad23f397f029a947d55a4.html



 
  © 2014-2022 ITdaan.com 联系我们: