- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 html 页面中放置了一段 php 代码。我正在使用 href,但链接无效。这是我的 html+php 代码:
<div class="panel-body">
<div class="row">
<div class="col-md-12 space20">
<button class="btn btn-green add-row">
Add New <i class="fa fa-plus"></i>
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover" id="sample_2">
<?php
$servername = "localhost";
$username = "hevak_neshat";
$password = "shir moz peste";
$dbname = "hevak_android_api";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM beacons";
$result = $conn->query($sql);
if($result -> num_rows > 0)
{
echo "<thead>
<tr><th>Major number</th>
<th>Minor number</th>
<th>Client</th>
<th>Location</th>
<th>Link to ad</th>
<th>Attachment</th>
<th>Edit</th>
</tr> ;</thead>";
echo "<tbody>";
while($row = $result -> fetch_assoc())
{
echo "<tr><td>" .$row["major"]. "</td><td>" .$row["minor"]. "</td><td>" .$row["client"]. "</td><td>" .$row["geolocation"]. "</td><td>" .$row["linktoadd"]. "</td><td>" .$row["attacment"] . "</td><td>";
echo "<a href=\"#\" class =\"edit-row\" >";
echo "Edit";
echo "</a></td>";
echo "</tr>";
}
echo "</tbody></table>";
} else {
echo "no results";
}
?>
以下是与 html 相关的我的 .js 代码的一部分:
$('#sample_2').on('click', '.edit-row', function(e) {
e.preventDefault();
if (actualEditingRow) {
if (newRow) {
oTable.fnDeleteRow(actualEditingRow);
newRow = false;
} else {
restoreRow(oTable, actualEditingRow);
}
}
var nRow = $(this).parents('tr')[0];
editRow(oTable, nRow);
actualEditingRow = nRow;
});
var oTable = $('#sample_2').dataTable({
"aoColumnDefs" : [{
"aTargets" : [0]
}],
"oLanguage" : {
"sLengthMenu" : "Show _MENU_ Rows",
"sSearch" : "",
"oPaginate" : {
"sPrevious" : "",
"sNext" : ""
}
},
"aaSorting" : [[1, 'asc']],
"aLengthMenu" : [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"] // change per page values here
],
// set the initial value
"iDisplayLength" : 10,
});
$('#sample_2_wrapper .dataTables_filter input').addClass("form-control input-sm").attr("placeholder", "Search");
// modify table search input
$('#sample_2_wrapper .dataTables_length select').addClass("m-wrap small");
// modify table per page dropdown
$('#sample_2_wrapper .dataTables_length select').select2();
// initialzie select2 dropdown
$('#sample_2_column_toggler input[type="checkbox"]').change(function() {
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var iCol = parseInt($(this).attr("data-column"));
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis(iCol, ( bVis ? false : true));
});
};
return {
//main function to initiate template pages
init : function() {
runDataTable_example1();
runDataTable_example2();
}
};
我的确切问题是当我删除 php 部分时“编辑”是可点击的并且工作正常。但是当我放置 php 以便能够获取我的数据库数据时,“编辑”仍然是一个链接,但是当您单击它时没有任何反应。我找不到这个问题的原因
更新:这是我的浏览器提供的 html:
<div class="panel-body">
<div class="row">
<div class="col-md-12 space20">
<button class="btn btn-green add-row">
Add New <i class="fa fa-plus"></i>
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover" id="sample_2">
<thead>
<tr>
<th>Major number</th>
<th>Minor number</th>
<th>Client</th>
<th>Location</th>
<th>Link to ad</th>
<th>Attachment</th>
<th>Edit</th>
</tr>
</thead><tbody><tr><td>2</td><td>5</td><td>noxel</td><td>16253</td><td>www.noxel.com</td><td>test</td><td><a href='#' class ='edit-row' >Edit<script>
$(document).on("click","edit-row",function(event){
alert("m here");
});
</script></a></td></tr><tr><td>7</td><td>9</td><td>nox</td><td>123456</td><td>www.digikla.com</td><td>jhhfdbc</td><td><a href='#' class ='edit-row' >Edit<script>
$(document).on("click","edit-row",function(event){
alert("m here");
});
</script></a></td></tr><tr><td>0</td><td>0</td><td>fgfh</td><td>645312</td><td>wwwwwwwwwwwww</td><td>wwwwwwwww</td><td><a href='#' class ='edit-row' >Edit<script>
$(document).on("click","edit-row",function(event){
alert("m here");
});
</script></a></td></tr></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- end: PAGE CONTENT-->
</div>
</div>
<!-- end: PAGE -->
</div>
最佳答案
You need not to write
script
inphp-loop
. Also note that".edit-row"
is valid selector for classes not"edit-row"
不要忘记阻止 <a>
元素的默认行为。使用 Event.preventDefault()
将您的 script
放在 body( </body>
) 标签之前。
试试这个:
$(document).on("click", ".edit-row", function(event) {
event.preventDefault();
alert("m here");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="panel-body">
<div class="row">
<div class="col-md-12 space20">
<button class="btn btn-green add-row">
Add New <i class="fa fa-plus"></i>
</button>
</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-hover" id="sample_2">
<thead>
<tr>
<th>Major number</th>
<th>Minor number</th>
<th>Client</th>
<th>Location</th>
<th>Link to ad</th>
<th>Attachment</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>5</td>
<td>noxel</td>
<td>16253</td>
<td>www.noxel.com</td>
<td>test</td>
<td><a href='#' class='edit-row'>Edit</a>
</td>
</tr>
<tr>
<td>7</td>
<td>9</td>
<td>nox</td>
<td>123456</td>
<td>www.digikla.com</td>
<td>jhhfdbc</td>
<td><a href='#' class='edit-row'>Edit</a>
</td>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>fgfh</td>
<td>645312</td>
<td>wwwwwwwwwwwww</td>
<td>wwwwwwwww</td>
<td><a href='#' class='edit-row'>Edit</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
关于javascript - href 链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506123/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!