2016-07-07 15 views
1

私は一連のチェックボックスを作成しました。値とid要素を取得できるかどうかは疑問でした。私は、HTML形式で次のチェックボックスを持っている場合たとえば、:"id"と "value"要素をチェックボックスから取得できますか?

<html> 
<body> 
    <form action="formInput.php" method="post"> 
     <table border="1" width="100%"> 
     <thead><p style="font-family:Arial" style="font-size:15px">This is my Form.</p></thead> 
     <tr> 
      <td width="33%" ><input type="hidden" id="item_1" name="interventions[]" value="false" /> 
      <input type="checkbox" id="item_1" name="interventions[]" value="true" /> Item 1</td> 
      <td width="33%"><input type="hidden" id="item_2" name="interventions[]" value="false" /> 
      <input type="checkbox" id="item_2" name="interventions[]" value="true" /> Item 2</td> 
     <td width="33%"><input type="hidden" id="item_3" name="interventions[]" value="false" /> 
      <input type="checkbox" id="item_3" name="interventions[]" value="true" /> Item 3</td> 
     </tr> 
    </table> 
</body> 
<html> 

は、ためのid要素やforeachループを持つことが可能でしょうか?事前に

おかげで、

-Kenny

答えて

-1
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script> 
<script> 
    //click checkbox event 
    $(':checkbox').click(function(){ 
     alert($(this).attr('id')); 
    }); 
    //or like this 
    var ids = []; 
    var values = []; 
    $(':checkbox').each(function(i,e){ 
     ids.push($(this).attr('id')); 
     values.push($(this).val()); 
    }); 
    console.log('ids:'+ids); //ids:item_1,item_2,item_3 
    console.log('values:'+values); //values:true,true,true 
</script> 
0
$xml=simplexml_load_string($html); 
$result=$xml->xpath('//input[@type="checkbox"]'); 
for ($el in $result) { 
    $id=(string)$el->attributes()['id']; 
    $value=(string)$el->attributes()['value']; 
    $checkboxes[$id]=$value; 
} 

http://php.net/manual/en/book.simplexml.php

関連する問題