不能将文本字符串传递给jquery函数? [英] cant pass text string into jquery function?

查看:144
本文介绍了不能将文本字符串传递给jquery函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是脚本

  $(body)。append(< div id = \debug\>+ $(message)+< / div> ):
}
debug(在div中显示此调试消息);

这是我得到的结果html

 < div id =debug> [object Object]< / div> 

我希望的是这个

 < div id =debug>在div< / div>中显示调试消息。 


解决方案

您正在粘贴一个对象,$(message) ,而不是可变消息。尝试这样:

  function debug(message){
$(body)。append(< div id = \debug\>+ message +< / div>):
}


What's wrong with my jquery script?

Here's the script

function debug(message){
  $("body").append("<div id=\"debug\">"+ $(message) +"</div>"):
}
debug("show this debug message in the div");

Here's the resulting html I get

<div id="debug">[object Object]</div>

The html that I expect is this

<div id="debug">show this debug message in the div</div>

解决方案

You are pasting an object in, $(message), instead of the variable message. Try this:

    function debug(message){
      $("body").append("<div id=\"debug\">"+ message +"</div>"):
    }

这篇关于不能将文本字符串传递给jquery函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆