0

我希望 Javascript 提醒整个员工姓名(名字和姓氏),但是使用此代码,由于某种原因它只显示名字。关于如何解决这个问题的任何想法?

这是我的代码:

if ( $even1 % 2) 
    echo "<option value=". $employee_firstname . " " . $employee_lastname . ">". $employee_firstname . " " . $employee_lastname . "</option>";
else
    echo "<option value=". $employee_firstname . " " . $employee_lastname . ">". $employee_firstname . " " . $employee_lastname . "</option>";

的JavaScript:

var List = document.getElementById('slcEmp');
var x = 0;

for (x = 0; x < List.length; x++) {
    if (List[x].selected) {
        alert(List[x].value);
    }
}
4

1 回答 1

0

您需要将属性值放在引号中,因为它包含一个空格:

echo "<option value='". htmlentities($employee_firstname) . " " . htmlentities($employee_lastname) . "'>". $employee_firstname . " " . $employee_lastname . "</option>";
                    ^                                                                                 ^

htmlentities()如果名称包含特殊字符(例如O'Leary) ,您还应该使用它。

于 2013-08-06T06:56:01.507 回答