如何使用 JQuery 为跨度设置值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1491743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to set a value for a span using JQuery
提问by useranon
How to set a value for a span using JQuery..
如何使用 JQuery 为跨度设置值..
For example… Below is my span
例如……下面是我的跨度
<span id="submittername"></span>
in my JQuery code…
在我的 JQuery 代码中...
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function($){
var invitee = $.ajax({
type: "GET",
url: "http://localhost/FormBuilder/index.php/reports/getInvitee/<?=$submitterid;?>",
async: false
}).responseText;
var invitee_email=eval('(' + invitee + ')');
var submitter_name=$.map(invitee_email.invites, function(j){
return j.submitter;
});
alert(submitter_name); // alerts correctly
$("#submittername").text(submitter_name); //but here it is not working WHy so??????
});
回答by cletus
You can do:
你可以做:
$("#submittername").text("testing");
or
或者
$("#submittername").html("testing <b>1 2 3</b>");
回答by Santosh Ganacharya
You are using jQuery(document).ready(function($) {}
means here you are using jQuery
instead of $
. So to resolve your issue use following code.
您在jQuery(document).ready(function($) {}
这里使用的是手段,jQuery
而不是$
. 因此,要解决您的问题,请使用以下代码。
jQuery("#submittername").text(submitter_name);
This will resolve your problem.
这将解决您的问题。
回答by Steerpike
You're looking for the wrong selector id:
您正在寻找错误的选择器 ID:
$("#submitter").text(submitter_name);
should be
应该
$("#submittername").text(submitter_name);
回答by Rita Chavda
You can use this:
你可以使用这个:
$("#submittername").html(submitter_name);
回答by Jorge Santos Neill
The solution that work for me is the following:
对我有用的解决方案如下:
$("#spanId").text("text to show");