【发布时间】:2017-11-28 14:01:31
【问题描述】:
在我的代码中
<script>
$(document).on('click', 'a#coin', function(){
// get month
var val = $(this).attr('data-id');
$.post('alert.php', {coin: val}, function(data){
console.log(data);
});
});
</script>
这是模式的数据切换链接
<a id="coin" href="#" data-id="BTC" data-toggle="modal" data-target="#alertmodal"><i class="fa fa-bell fa-lg" title="Set Alert for BTC" style="color:orangered"></i></a>
而在 alert.php 我只是有
$coin = $_POST['coin'];
echo $coin;
模式弹出很好,只是没有传递 data-id 值 不确定我做错了什么
添加了更多代码
<?php
require('alert.php');
?>
<html><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css.css" rel="stylesheet" type="text/css">
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script>
$(document).ready(function(){
$("#liveprices").load("liveprices.php");
setInterval(function() {
$("#liveprices").load("liveprices.php");
}, 5000);
});
</script>
</head><body>
这里讨论的函数是在文档末尾加载的
【问题讨论】:
-
我不确定它是否会有所作为,但 jQuery 有一个用于访问
data-*属性的内置函数。$(this).data('id') -
它对我有用。我在 alert.php 中获得硬币价值。打开您的控制台并查找错误
-
没有没有变化:(
-
说 bootstrap.min.js 需要 Jquery,尽管 jquery 是在它上面加载的
-
我认为这里的代码没有任何问题。你可以为你的 bootstrap.min.js 试试这个吗? cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/…
标签: javascript php jquery twitter-bootstrap