我无法获得我的选择框的全部价值。
在我的剧本中:
$company = $("#company").val();
在我的HTML中:
<select id='company' name='company'>
<?php
$con = mysqli_connect("localhost", "root", "", "project") or die("error" . mysql_error($con));
$qry = "SELECT * FROM company";
$result = mysqli_query($con, $qry);
while ($row = mysqli_fetch_array($result))
{
echo "<option value=" . $row['company_name'] . ">" . $row['company_name'] . "</option>";
}
?>
</select>
$company
只有第一个字。
答案 0 :(得分:2)
尝试将单引号置于值
之后echo"<option value='".$row['company_name']. "'>" .$row['company_name']. "</option>";
^^^ ^^^
答案 1 :(得分:0)
试试这个。像这样改变你的jquery和选项标记行
$( "#company option:selected" ).text();
<select id='company' name='company'>
<?php
$con=mysqli_connect("localhost","root","","project") or die("error" . mysql_error($con));
$qry="SELECT * FROM company";
$result=mysqli_query($con,$qry);
while($row=mysqli_fetch_array($result))
{
echo"<option value='".$row['company_name']. "'>" .$row['company_name']. "</option>";
}
?>
</select>