相关疑难解决方法(0)

.prop()vs .attr()

所以jQuery 1.6具有新功能prop().

$(selector).click(function(){
    //instead of:
    this.getAttribute('style');
    //do i use:
    $(this).prop('style');
    //or:
    $(this).attr('style');
})
Run Code Online (Sandbox Code Playgroud)

或者在这种情况下,他们做同样的事情?

如果我有转用prop(),所有的旧attr()电话,如果我切换到1.6将打破?

UPDATE

selector = '#id'

$(selector).click(function() {
    //instead of:
    var getAtt = this.getAttribute('style');
    //do i use:
    var thisProp = $(this).prop('style');
    //or:
    var thisAttr = $(this).attr('style');

    console.log(getAtt, thisProp, thisAttr);
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<div id='id' style="color: red;background: orange;">test</div>
Run Code Online (Sandbox Code Playgroud)

(另见这个小提琴:http://jsfiddle.net/maniator/JpUF2/)

控制台会记录getAttribute作为一个字符串,并attr作为一个字符串,但prop作为一个CSSStyleDeclaration,为什么?这对我未来的编码有何影响?

javascript jquery dom prop attr

2249
推荐指数
14
解决办法
57万
查看次数

jQuery获取textarea文本

最近我开始玩jQuery,并且已经关注了几个教程.现在我觉得使用它有点能干(这很简单),我觉得如果我能在我的网页上制作一个"控制台"会很酷(就像你在FPS游戏中一样按下'键' ,等),然后让Ajax本身回到服务器,以便做的事情.

我原本认为最好的方法是在textarea中获取文本,然后拆分它,或者我应该使用keyup事件,将返回的键码转换为ASCII字符,将字符附加到字符串并将字符串发送到服务器(然后清空字符串).

我找不到任何关于从textarea获取文本的信息,我得到的只是密钥信息.另外,如何将返回的键码转换为ASCII字符?

javascript ajax jquery

474
推荐指数
7
解决办法
71万
查看次数

标签 统计

javascript ×2

jquery ×2

ajax ×1

attr ×1

dom ×1

prop ×1