相关疑难解决方法(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万
查看次数

名称=''的无效表单控件不可聚焦

我的网站上有一个严重的问题.在Google Chrome中,有些客户无法前往我的付款页面.在尝试提交表单时,我收到此错误:

An invalid form control with name='' is not focusable.
Run Code Online (Sandbox Code Playgroud)

这是来自JavaScript控制台.

我读到问题可能是由于隐藏字段具有必需属性.现在的问题是我们使用的是.net webforms必需的字段验证器,而不是html5必需属性.

这个错误似乎是随机的.有没有人知道解决方案?

html validation html5

611
推荐指数
17
解决办法
45万
查看次数

标签 统计

attr ×1

dom ×1

html ×1

html5 ×1

javascript ×1

jquery ×1

prop ×1

validation ×1