[英]value doesn't change when I'm trying to toggling the checkbox
I have this code, when im trying to toggle the checkbox (I can view the changes in inspect), the value of the checkbox doesnt change 我有这个代码,当我试图切换复选框(我可以查看检查中的更改)时,复选框的值不会改变
<div class="checkbox checkbox-success"> <input type="checkbox" name="NCONF_RSN1" id="NCONF_RSN1" value=""> <label> Facility is far </label> <input type="hidden" name="NCONF_RSN1" id="NCONF_RSN1" value=""/> </div>
checkout with value 结账有价值
if ($(this).prop("checked") == true) {
$("h2 span").text(checkBoxval);
}
$(document).ready(function() { var $checkBox = $("[type='checkbox']"); var checkBoxval = $checkBox.val(); $("h2 span").text(checkBoxval); $checkBox.on("click", function() { if ($(this).prop("checked") == true) { $("h2").show(); $("h2 span").text(checkBoxval); } else { $("h2").hide(); } }) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="checkbox checkbox-success"> <input type="checkbox" name="NCONF_RSN1" id="NCONF_RSN1" value="My Checkbox value" checked="true"> <label> Facility is far </label> <input type="hidden" name="NCONF_RSN1" id="NCONF_RSN1" value="" /> <h2>Your value is <span></span></h2> </div>
好吧,我们看不到你的js代码但是,你不应该像你用NCONF_RSN1那样复制一个id属性
You given the same id to both input element, give two different id. 你给两个输入元素都给了相同的id,给出两个不同的id。 Then it will work
然后它会工作
Figured out my problem, added "_" on hidden id 找出我的问题,在隐藏的id上加上“_”
Instead of id="NCONF_RSN1" i used id="NCONF_RSN1_". 而不是id =“NCONF_RSN1”我使用了id =“NCONF_RSN1_”。
i just tried it, i dont know how it worked. 我刚尝试过,我不知道它是如何工作的。
<div class="checkbox checkbox-success"> <input type="checkbox" name="NCONF_RSN1" id="NCONF_RSN1" value=""> <label> Facility is far </label> <input type="hidden" name="NCONF_RSN1" id="NCONF_RSN1_" value=""/> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.