Home  >  Article  >  Backend Development  >  得到的checkbox的value不知道从哪儿出来的/?解决思路

得到的checkbox的value不知道从哪儿出来的/?解决思路

WBOY
WBOYOriginal
2016-06-13 13:35:55904browse

得到的checkbox的value不知道从哪儿出来的/?
我从数据库里面获得了result,把roomname字段作为了checkbox的value,在javascript脚本的summitdata函数和mcustom.php中的得到的数据中间怎么都加了/?
1.
echo "

";
echo "";
while($row=mysql_fetch_array($result))
{
  echo "";
  echo "";
  echo "";//此处没有/
  echo "";  

echo "";
echo "
" . $row['roomname'] . "
";
echo "
";
2.javascript部分
function checkchecked(checkboxs)
{

  for(var i=0;i   {
  if(checkboxs[i].checked)  
  {
  alert(checkboxs[i].value);//此处得到的checkboxs[i].value的值101/,已经被加了/
  return true;
  }
   
  }
  alert("Please select the room.");
  return false;
}
function submitdata()
{
  var checkboxs=document.getElementsByName("selectrooms[]");
  var checked=checkchecked(checkboxs);
  if(checked)
  {
  var form=document.getElementById("roomlist");
  form.submit();
  }
  else
  {
  return false;
  }
}
3.mcustom.php中得到的
  if(isset($_GET["selectrooms"]))
  {
  $selectrooms=$_GET["selectrooms"];
  foreach($selectrooms as $item)
  {
  echo "";
  echo "" .$item . "";//此处也有/
  echo "";
  }
  }

------解决方案--------------------
value=" . $row['roomname'] . "/>";得出的结果大概是 value=roomnamevalue/>
value和/>之间没有空格,所以浏览器认为value=roomnamevalue/ 。建议在任何属性都加上""包含属性值
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn