2015-09-08 31 views
0

这是我使用jQuery的脚本的一部分。脚本中的jQuery attr和prop组合

 jQuery(".disabableInputField").addClass("disabledInputField"); 
     cstaIpVal[0] = jQuery("#private-circuit-to-csta-subnet").val(); 
     cstaIpVal[1] = jQuery("#private-circuit-to-csta-subnet\\.netmask").val(); 
     jQuery("#private-circuit-to-csta-subnet\\.netmask").val(""); 
     jQuery("#private-circuit-to-csta-subnet").val(""); 
     jQuery(".disabableInputField").attr("disabled",true);   
     jQuery("#private-circuit-to-csta-subnet\\.netmask").prop("path", ""); 
     jQuery("#private-circuit-to-csta-subnet").prop("path",""); 

问题是,为什么调用prop和attr的组合不起作用。如果我拨打attr("disabled",true),那么属性集prop("path","")不起作用。当我切换订单时,属性设置不起作用。我无法通过prop实现设置禁用的属性。我怎样才能结合attr和道具呼叫?或者我如何通过prop调用设置html元素的禁用属性?

谢谢。

+0

你滥用这两种方法。 'prop'用于'disabled','attr'用于定制属性('path') – hindmost

回答

1

我想这是因为滥用方法。使用“prop”设置属性,使用“attr”设置属性。不是反之。以下工作适合我。

jQuery(".disabableInputField").prop("disabled", true); 

参见:https://learn.jquery.com/using-jquery-core/faq/how-do-i-disable-enable-a-form-element/

也许这样的:

<input type="text" id="test" /> 
<script type="text/javascript"> 
    jQuery("#test").prop("disabled",true); 
    jQuery("#test").attr("path", ""); 
</script> 
<!-- result --> 
<input disabled="" id="test" type="text" path=""> 
+0

更改后的代码: 'jQuery(“#private-circuit-to-csta-subnet \\ .netmask”)prop “禁用”,TRUE); 。jQuery的( “#私人电路到CSTA子网”)丙( “禁用”,TRUE); jQuery(“#private-circuit-to-csta-subnet \\ .netmask”)。attr(“path”,“”); jQuery(“#private-circuit-to-csta-subnet”)。attr(“path”,“”);' path is correct,it is empty,but disabled attribute does not work,it's still a editable field :/我现在很困惑 –

+0

请显示您的html标记为#private-circuit-to-csta-subnet – unconnected

+0

'' 它无法更改,我需要使用此版本 谢谢你的帮助。 –