javascript - 用angular調用PHP中的數據,點擊按鈕不能執行js函數,原生JS也試過,失敗。
黄舟
黄舟 2017-06-17 09:15:28
[PHP讨论组]

<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<script src="https://cdn.bootcss.com/angular.js/1.6.3/angular.min.js"></script>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

</head>
<style>

*{margin: 0;padding:0;}
table{width:100%;height:auto;text-align: left;}
tr{border:1px solid #eee;}
table,tr,td{border-collapse: collapse;}
tr>th{width:25%;height:auto;}
.app_save_box{width:50px;height:30px;background:#00B83F;color:#fff;text-align: center;line-height: 30px;margin: 20px auto;}

</style>
<body>
<p ng-app="myApp" ng-controller="customersCtrl">

<form action="">
    <table>
        <tr>
            <th>序号</th>
            <th>应用名</th>
            <th>网址</th>
        </tr>
        <tr ng-repeat="x in names">
            <td>{{ x.id }}</td>

            <td>
                <input type="text" value="{{ x.name }}" disabled="disabled"/>
                <button class="app_name_change">修改</button>
            </td>
            <td>
                <input type="text" value="{{ x.url }}" disabled="disabled"/>
                <button class="app_url_change">修改</button>
            </td>
            <td>
                <button class="app-delete">删除该项</button>
            </td>
        </tr>
    </table>
</form>
<p class="app_save_box">保存</p>

</p>

<script>

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("data.php")
            .then(function (result) {
                $scope.names = result.data.records;
            });
});

$(".app_name_change").on("click",function(){
    $(this).prev().removeAttr("disabled")
})

</script>
</body>
</html>


php代碼

<?php
echo <<<EOT
{
"records":[
{"id":"1","name":"新浪","url":"http://www.sina.com"},
{"id":"2","name":"百度","url":"http://www.baidu.com"}
]
}
EOT;
?>

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(1)
迷茫

添加header('Content-Type: application/json');让输出的内容是json

<?php
header('Content-Type: application/json');

echo <<<EOT
{
"records":[
{"id":"1","name":"新浪","url":"http://www.sina.com"},
{"id":"2","name":"百度","url":"http://www.baidu.com"}
]
}
EOT;
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号