在jQuery中添加属性
我如何添加一个属性到特定的HTML标签在jQuery中?
例如,像这个简单的HTML:
<input id="someid" /> 然后添加一个属性disabled =“true”,如下所示:
 <input id="someid" disabled="true" /> 
	
 你可以像这样使用attr添加属性: 
 $('#someid').attr('name', 'value'); 
 但是,对于像checked , disabled和readonly这样的DOM属性来说,正确的方法是使用prop (比如JQuery 1.6)。 
 $('#someid').prop('disabled', true); 
最好的解决scheme:从jQuery v1.6开始,你可以使用prop()来添加一个属性
 $('#someid').prop('disabled', true); 
 删除它,使用removeProp() 
 $('#someid').removeProp('disabled'); 
 Reference 
另请注意,不应使用.removeProp()方法将这些属性设置为false。 一旦原生财产被删除,它不能再被添加。 请参阅.removeProp()以获取更多信息。
 你可以使用jQuery的.attr函数来设置属性。 删除它们是通过.removeAttr函数完成的。 
 //.attr() $("element").attr("id", "newId"); $("element").attr("disabled", true); //.removeAttr() $("element").removeAttr("id"); $("element").removeAttr("disabled"); 
 $('#someid').attr('disabled', 'true'); 
 $('#someid').attr('disabled', 'true'); 
 $('.some_selector').attr('disabled', true); 
这可能会更有帮助….
 $("element").prop("id", "modifiedId"); //for boolean $("element").prop("disabled", true); //also you can remove attribute $('#someid').removeProp('disabled'); 
 $('#yourid').prop('disabled', true); 
添加属性如下:
 $('#Selector_id').attr('disabled',true);