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/dart/3.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所需的attr_Javascript_Jquery_Html_Onclick - Fatal编程技术网

Javascript 删除jquery所需的attr

Javascript 删除jquery所需的attr,javascript,jquery,html,onclick,Javascript,Jquery,Html,Onclick,当我选中livelongwarranty复选框时,是否可以从输入字段“保修期限”中删除所需的attr years warrenty<label id="warrantyDurationlabel"><input name="warranty_duration" type="number" placeholder="aantal jaren garantie" min="1" size="25" required /></label> levenlang&l

当我选中livelongwarranty复选框时,是否可以从输入字段“保修期限”中删除所需的attr

years warrenty<label id="warrantyDurationlabel"><input name="warranty_duration" type="number" placeholder="aantal jaren garantie" min="1" size="25" required /></label>
  levenlang<label id="livelongwarranty"><input name="livelong_warranty" type="checkbox" onclick="js/warrantyrequired.js" /></label>

我必须向输入中添加id属性,因为它们没有id,您可以搜索名称,但我认为这不是您想要的。Name主要用于通过HTML/PHP表单发送的post/get数据,id用于引用、设置样式以及更进一步的JavaScript元素

$“livelong_保修”。关于“更改”,函数{ $“保修期限”.attr'required',$“livelong\u保修”。is:已选中; console.log$'warranty_duration'.attr'required'; }; 战争年代
levenlangremoveAttr很好。但若要重新添加属性,您需要给它一个值:.attr'required',true,只有一个参数,.attr只返回值,它不会更改任何内容。html中没有保修期限和寿命保修。@Barmar I addad true to.attr,但这似乎不起作用,我仍然收到这样的信息:现场保修期为required@wes您应该只加载一个版本的jQuery。@wes您是否记得将id=warranty\u duration添加到文本框中,并将id=livelong\u warranty添加到复选框中?代码的内容是反向的。选中复选框时,不需要输入。所以它应该是!$'“livelong_保修”是:checked@Barmar可能会干扰jquery:如果没有submit按钮,如何获得关于所需字段的消息?
$('#livelong_warranty').change(function () {
if($(this).is(':checked') {
    $('#warranty_duration').removeAttr('required');
} else {
    $('#warranty_duration').attr('required');
}});