How to get the check box state when it is changed. I am using zurb foundation

<label for="checkbox3"><input id="checkbox2" type="checkbox" name="chk[2]"></input>
   <span class="custom checkbox" onclick="toggleState(2)"></span>
   Check Box 1
</label>

But in function state prior to clicked is shown. How should i get the latest value Please Help

有帮助吗?

解决方案

I would remove the onclick="toggleState(2)" and try some jquery code similar to:

$('#checkbox2').on('change', function() {
  console.log($(this).is(':checked'));
});

Also, you should change your label to <label for="checkbox2"> rather than <label for="checkbox3"> as an element with the id checkbox3 doesn't exist.

It would also help if you could mention what version of Foundation you are using.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top