weixin_33720956 2015-11-10 13:23 采纳率: 0%
浏览 34

DOM与PHP输出不匹配

I have the following PHP script:

    function drawDepts(mysqli $con, $defaultDept) {

    $deptQuery = "SELECT * FROM depts";
    $deptResult = $con->query($deptQuery);
    global $request;

    echo "<select id='targetDept' width='200' style='width:200px;' onchange='updateRequest(".$request['id'].", 'targetDept', $('#targetDept').val()'>";

    while ($deptRow = $deptResult->fetch_array(MYSQL_ASSOC)) {
        echo "<option value='" . $deptRow['id'] . "' ";
        if ($deptRow['id'] == $defaultDept) {
            echo "selected='selected'";
        }
        echo ">" . $deptRow['name'] . "</option>";
    }

    echo "</select>";
}

This basically just creates a select box with options from a DB. The onchange allows the user to update the DB without re-loading the page (ajax).

The weird part is the DOM shows this (IE 11):

<select id="targetDept" style="width: 200px;" onchange="updateRequest(212, " $('#targetdept').val())'="" targetdept',="" width="200">

Specifically, why are there " , ="" and width="200px"

echoing the javascript function as text works just fine... It seems that IE is screwing up the onchange tag.

  • 写回答

1条回答 默认 最新

  • weixin_33704591 2015-11-10 13:28
    关注

    You have a syntax error on your onchange with ' and " use \ to escape the ' used within your onChange with the ''s

    echo "<select id='targetDept' width='200' style='width:200px;' onchange='updateRequest(".$request['id'].", \"targetDept\", $(\"#targetDept\").val())'>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stc15f2k60s2单片机关于流水灯,时钟,定时器,矩阵键盘等方面的综合问题
  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开