简体   繁体   English

当我试图切换复选框时,值不会改变

[英]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.

相关问题 当我尝试移动跨度时,appendChild不起作用 - appendChild doesn't work when I'm trying to move span 切换复选框仅选中,不取消选中 - Toggling checkbox only checks, doesn't uncheck 我正在尝试获取 cookie 的值,但它有一个。 在前面,它没有设定它的价值? - I'm trying to get a cookie's value, but it has a . infront and it doesn't set it's value? 我正在尝试显示选择到 div 中的每个复选框的值 - I'm trying to display the value of each checkbox selected into a div 当另一个复选框“激发”时,不会触发Checkbox .change()事件 - Checkbox .change() event doesn't fire, when “fired” by another checkbox 当我按回车键时,我试图阻止默认行为,但它不起作用 - I'm trying to prevent default behavior when I hit enter but it doesn't work 我正在尝试获取文本输入的值,但它无法正常工作 - I'm trying to get value of a text input but it doesn't work correctly 当我尝试引用其他模式的对象时,为什么猫鼬引用对我不起作用? - Why doesn't mongoose ref work for me when I'm trying to reference objects of another schema? 当我使用 setstate 调用 function 时,State 值不会改变 - State value doesn't change when I call a function with setstate 我正在尝试使用 Heroku 创建一个不和谐的机器人,当我在本地运行它时它可以工作,但是当我将它部署在 Heroku 上时它不起作用 - I'm trying to create a discord bot with Heroku, when I run it locally it works, but it doesn't work when I deploy it on Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM