与 jquery 连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1526605/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:38:31  来源:igfitidea点击:

concatenate with jquery

jqueryconcatenation

提问by user79127

I'm trying to concatenate a string in a div with jQuery. Here is my code:

我正在尝试使用 jQuery 连接 div 中的字符串。这是我的代码:

var server = 'server name: '
$('#div').load('myservername.aspx');

I'd like to display:

我想显示:

server name: myserver

服务器名称:myserver

How can I best achieve this?

我怎样才能最好地实现这一目标?

回答by Ryu

Tweaking what you have

调整你所拥有的

$('#div').load('myservername.aspx');
$('#div').prepend('Server Name:')

Could also do

也可以做

$.get("myservername.aspx", function(data){

$('#div').html('Server name: ' + data)

});

回答by slf

jQuery manipulation docshave these little codes to append

jQuery操作文档有这些要附加的小代码

$("p").append("<strong>Hello</strong>");

回答by devpl

I'm assuming that you have an html with the following html code

我假设您有一个包含以下 html 代码的 html

<div id="some_id">
</div>

and you want to load the div with server name: myserver (?).

并且您想使用服务器名称加载 div:myserver (?)。

If so, i think you can use

如果是这样,我想你可以使用

$('#some_id').text("server name: myserver");