我正在使用 jquery,我需要将一些文本附加到变量:
$("document").ready(function(){
var i="this is text";
$(i).append("aa");
alert(i);
})
最佳答案
您当然可以为此创建一个 jQuery 插件
$.fn.appendString = function(str) {
return this.selector + str;
}
$(document).ready(function(){
var i = "this is text";
alert( $(i).appendString("aa") );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
但它是连接字符串
var i = "this is text";
i = i + "aa"; // it's now "this is textaa"
请注意,$("this is text")
并不是真正有效的任何内容,jQuery 并不真正处理字符串
关于javascript - 如何将一些文本附加到变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26819287/