所以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 setVal函数显示它们的值进行编辑,我添加了一个额外的复选框字段,我传递了一个值,
在这里,我想检查是否.set("value",""),然后应该检查此复选框,否则取消选中,
我这样做是因为使用了两个div,但我对此感到不舒服,还有其他解决办法吗?
if(value == 1) {
$('#uncheck').hide();
$('#check').show();
} else{
$('#uncheck').show();
$('#check').hide();
}
Run Code Online (Sandbox Code Playgroud) 如何在jQuery中将属性添加到特定的HTML标记中?
例如,像这个简单的HTML:
<input id="someid" />
Run Code Online (Sandbox Code Playgroud)
然后添加一个属性disabled ="true",如下所示:
<input id="someid" disabled="true" />
Run Code Online (Sandbox Code Playgroud) 如何有条件地添加元素属性,例如checked复选框?
以前版本的Angular已经NgAttr和我认为NgChecked哪些似乎都提供了我所追求的功能.但是,Angular 2中似乎不存在这些属性,我看不到提供此功能的其他方法.
我有一个表单输入元素,并希望更改其title属性.这必须很容易,但由于某种原因,我找不到如何做到这一点.这是怎么做的,我应该在哪里以及如何搜索如何做到这一点?
我很难搞清楚这一点.我有两个复选框(将来会有更多):
checkSurfaceEnvironment-1checkSurfaceEnvironment-2基本上,我想编写一个if语句并测试是否检查了其中一个而未检查另一个.完成以下操作的最简单方法是什么:
if ( $("#checkSurfaceEnvironment-1").attr('checked', true) &&
$("#checkSurfaceEnvironment-2").is('**(NOT??)** :checked') ) {
// do something
}
Run Code Online (Sandbox Code Playgroud) 表达式喜欢Element.getAttribute("id")并Element.id返回相同的东西.
当我们需要HTMLElement对象的属性时应该使用哪一个?
有没有使用这些方法,如任何跨浏览器的问题getAttribute()和setAttribute()?
或者直接访问对象属性与使用这些属性方法之间的性能有何影响?
我有一个HTML输入,其中包含值中的链接.
<input type = 'text' value = 'http://www.link.com' id = 'link' />
Run Code Online (Sandbox Code Playgroud)
我正在使用jQuery来更改某个事件的值.
$('#link').val('new value');
Run Code Online (Sandbox Code Playgroud)
上面的代码更改了文本框的值,但没有更改代码中的值(value ='http://www.link.com'保持不变).我还需要值=''来改变.
我看到React 16允许将属性传递给DOM.那么,这意味着'class'可以用来代替className,对吧?
我只是想知道在类上使用className是否有好处,除了向后兼容以前版本的React.
我可以任意属性为JavaScript DOM对象,如添加<INPUT>或<SELECT>元素?或者,如果我不能这样做,有没有办法通过引用属性将我自己的对象与页面元素相关联?
jquery ×6
javascript ×5
dom ×3
html ×2
angular ×1
attr ×1
attributes ×1
forms ×1
if-statement ×1
jquery-ui ×1
prop ×1
reactjs ×1
tags ×1