Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery根据select将textarea更改为读写_Javascript_Jquery_Html - Fatal编程技术网

Javascript jquery根据select将textarea更改为读写

Javascript jquery根据select将textarea更改为读写,javascript,jquery,html,Javascript,Jquery,Html,我有一个表单中的文本区域,我想根据复选框从readyonly更改为readwrite。 在下面的jquery中,我需要设置为只读的textarea对象otherinjcomment,选中otherinj时设置为readwrite,未选中otherinj时设置为readonly $(function(){ $("#otherinj").change(function{ If($(this).is(':checked')){ $("#otherinjc

我有一个表单中的文本区域,我想根据复选框从readyonly更改为readwrite。 在下面的jquery中,我需要设置为只读的textarea对象otherinjcomment,选中otherinj时设置为readwrite,未选中otherinj时设置为readonly

$(function(){
    $("#otherinj").change(function{
        If($(this).is(':checked')){
            $("#otherinjcomment").prop('readonly',False)
        } 
        else{
            $("#otherinjcomment").prop('readonly',True)   
        }
    })
})
这是html

<div id="afterdesciption">
    <label for="otherinj">Other(Specify below)</label>
    <input type="checkbox" id="otherinj" name="otherinj" value="1">
</div>

<div>
    <textarea name="otherinjcomment" readonly="readonly"></textarea>
</div>

要使其只读然后读写,您可以相应地切换disabled属性。这里是一个工作示例,如果您有多个文本字段,则使用类作为选择器,而不是ID

$("#otherinj").change(function(){
  if($(this).is(':checked')){
    $("#otherinjcomment").attr("disabled","disabled"); 
  } 
  else{
    $("#otherinjcomment").removeAttr('disabled')
  }
})

要使其只读然后读写,您可以相应地切换disabled属性。这里是一个工作示例,如果您有多个文本字段,则使用类作为选择器,而不是ID

$("#otherinj").change(function(){
  if($(this).is(':checked')){
    $("#otherinjcomment").attr("disabled","disabled"); 
  } 
  else{
    $("#otherinjcomment").removeAttr('disabled')
  }
})

您的文本区域具有名称OtherInComment,而不是id。 您需要以下jquery代码:

$otherinj.changefunction{ 如果$this.is':选中'{ $[name=otherinjcomment].prop'readonly',false } 否则{ $[name=otherinjcomment].prop'readonly',true }
}; 您的文本区域具有名称OtherInComment,而不是id。 您需要以下jquery代码:

$otherinj.changefunction{ 如果$this.is':选中'{ $[name=otherinjcomment].prop'readonly',false } 否则{ $[name=otherinjcomment].prop'readonly',true }
};$otherinj.changefunction{确实有$otherinj.changefunction{。只是把副本弄乱了。请注意:如果->如果…也为False和True,则打字错误更改无效。仍然失败。$otherinj.changefunction{确实有$otherinj.changefunction{.只是把副本弄乱了.注意:If->If…还有False和true使排印更改无效.仍然失败.很好.我输入了id以与其他代码一致.最后的脚本如下.在禁用$otherinj.changefunction之前我还清空了字段{If$this.is':checked'{$otherinjcomment.removeAttr'disabled'}else{$otherinjcomment.val.attrdisabled,disabled}很好的捕获。我输入了与其他代码一致的id。下面是最终脚本。在禁用$otherinj.changefunction之前,我还清空了该字段。{如果$this.is':选中'{$otherinjcomment.removeAttr'disabled'}其他{$otherinjcomment.val.attrdisabled,disabled}