Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.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中选中复选框,如何更改复选框值_Javascript_Checkbox - Fatal编程技术网

如果在javascript中选中复选框,如何更改复选框值

如果在javascript中选中复选框,如何更改复选框值,javascript,checkbox,Javascript,Checkbox,我想在选中复选框时更改该值 我的HTML: <input class="checkbox" type="checkbox" name="textMessage" id="tm" value="0" /><span class="text">Unlimited text messages $5 / month</span> 选中我的复选框时,我的值仍然为0,我的JavaScript有什么问题吗?请检查此项 如果检查dev工具中的元素,您将看到value属性已更

我想在选中复选框时更改该值

我的HTML:

<input class="checkbox" type="checkbox" name="textMessage" id="tm" value="0" /><span class="text">Unlimited text messages $5 / month</span>
选中我的复选框时,我的值仍然为0,我的JavaScript有什么问题吗?

请检查此项

如果检查dev工具中的元素,您将看到value属性已更改为5。如果你想改变文本的实际内容,那会有点不同,但是如果你需要的话,请告诉我

$(".checkbox").on("change", function () {
    $(this).attr("value", 5);
});
无限制短信$5/
月

你被禁止进入谷歌了吗?这个问题表明缺乏研究。其他地方已经有很多这样做的例子。StackOverflow不是一个代码编写服务,它是一个问答网站。请复习。
$(".checkbox").on("change", function () {
    $(this).attr("value", 5);
});
<input class="checkbox" type="checkbox" name="textMessage" id="tm" value="0" 
onclick=this.value=5;alert(this.value)/><span class="text">Unlimited text messages $5 / 
month</span>