【问题标题】:Jquery text returning weird valuesJquery文本返回奇怪的值
【发布时间】:2013-11-06 19:41:27
【问题描述】:

我的代码产生了奇怪的输出,我只想获取一个元素的值,但它返回了某种代码。对不起,如果这是一个愚蠢的问题,我从 JavaScript 开始:

function clicarBotao(id){
    var text=$("#"+id).html;    
    alert(text);
}
</script>

<body>
...
<ul>
<li id="1" class="botaoMenu" onclick="clicarBotao(1)">Menu 1</li>
</ul>
...
</body>

警报返回:

function ( value ) {
        return jQuery.access( this, function( value ) {
            var elem = this[0] || {},
                i = 0,
                l = this.length;

            if ( value === undefined ) {
                return elem.nodeType === 1 ?
                    elem.innerHTML.replace( rinlinejQuery, "" ) :
                    undefined;
            }

代码并没有在这里结束...

【问题讨论】:

  • 避免使用数字作为 id....

标签: jquery return alert


【解决方案1】:

您需要html(),而不是html。它正在打印函数定义。

【讨论】:

    【解决方案2】:
    function clicarBotao(id){
       //var text=$("#"+id).html; you use html
        var text=$("#"+id).html();   //here use html() not html 
        alert(text);
    }
    

    参考.html()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 2013-04-26
      相关资源
      最近更新 更多