相关疑难解决方法(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删除disabled属性?

我必须首先禁用输入,然后单击链接以启用它们.

这是我到目前为止所尝试的,但它不起作用:

HTML:

<input type="text" disabled="disabled" class="inputDisabled" value="">
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#edit").click(function(event){
   event.preventDefault();
   $('.inputDisabled').removeAttr("disabled")
});
Run Code Online (Sandbox Code Playgroud)

这显示了我true,false但输入没有任何变化:

$("#edit").click(function(event){
   alert('');
   event.preventDefault();
   alert($('.inputDisabled').attr('disabled'));
   $('.inputDisabled').removeAttr("disabled");
   alert($('.inputDisabled').attr('disabled'));
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery disabled-input

368
推荐指数
7
解决办法
56万
查看次数

使用jQuery切换输入禁用属性

这是我的代码:

$("#product1 :checkbox").click(function(){
    $(this)
        .closest('tr') // Find the parent row.
            .find(":input[type='text']") // Find text elements in that row.
                .attr('disabled',false).toggleClass('disabled') // Enable them.
                .end() // Go back to the row.
            .siblings() // Get its siblings
                .find(":input[type='text']") // Find text elements in those rows.
                .attr('disabled',true).removeClass('disabled'); // Disable them.
});
Run Code Online (Sandbox Code Playgroud)

我如何切换.attr('disabled',false);

我似乎无法在Google上找到它.

jquery toggle attr

177
推荐指数
4
解决办法
17万
查看次数

如果...则按下按钮功能

我如何为这段代码做一个if ... then语句?

  $('body').on('click', '.icon-lock', function () {
        var lockedarea = $(this).parents(0).eq(2);
    $(lockedarea).find('input[type=text],input[type=checkbox],textarea,select').prop('disabled', true);
  });
Run Code Online (Sandbox Code Playgroud)

现在,当我点击它时,我想要发生的事情发生在那些输入变得不可编辑的时候.但是,我试图说,如果按下此按钮,则会发生这种情况.如果它再次按下,则.prop('disabled',false).然而,当我刚刚开始时,在做这类事情时我很容易感到困惑.

javascript jquery dom if-statement input

1
推荐指数
1
解决办法
117
查看次数

标签 统计

jquery ×4

javascript ×3

attr ×2

dom ×2

disabled-input ×1

if-statement ×1

input ×1

prop ×1

toggle ×1