如何调用表td标记内的Onload函数
How to Call Onload Function inside table td tag
Hiii Everone,
我想在加载td标签时检查条件。因此,我尝试在onload函数的帮助下检查条件。下面是一个例子,但我在onload中尝试的代码不起作用,请任何人帮助我解决这个问题。Sceneraio在td内,如果check_course内的条件大于1,则会显示按钮1或按钮2。
PHP代码
<?php
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d");
$time = date("Y-m-d H:i:s");
require "country.php";
$per_email=$_POST['per_email'];
$stream_name=$_POST['specialization_filter'];
$country_filter=$_POST['country_filter'];
$country = new country();
$users = $country->universities($stream_name,$country_filter);
if ( empty($users) ) {
?>
<br/><br/>
<?php echo "<span class='"alert alert-danger'">No universities Available For Your Search Results!!! </span> <br>" ;
}else{
?>
<div class="table-responsive" id="filter_universities">
<table class="table no-border">
<thead >
<tr class="row_univ">
<th class="university_sort" id="name_total_sort" status="asc" style="cursor:pointer">University
<i class="fa fa-caret-down font-grey-salsa"></i>
</th>
<th class="col-md-3">Program</th>
<th class="fee_structure" id="fee_total_sort" status="asc" style="cursor:pointer">Fee
<i class="fa fa-caret-down font-grey-salsa"></i>
</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
foreach ($users as $user){
$i++;
?>
<tr class="tr_bgs">
<td class="col-md-4">
<div class="row">
<div class="col-md-3">
<img src="images/university1.jpg" class="img-circle" width="62px" height="62px" alt="">
</div>
<div class="col-md-9">
<h5 class="bold fees">
<a target="_blank" class="university_class" mode="ambitious" cid="292"><?php echo $user['university']?> </a>
</h5>
<span class="font-grey-lite"><?php echo $user['country']?> </span>
</div>
</div>
</td>
<td>
<h5 class="bold fees"> <?php echo $user['course']?> </h5>
<span class="font-grey-lite"> <?php echo $user['stream_name']?> </span>
</td>
<td>
<h5 class="bold fees"><?php echo $user['fees']?> </h5>
<span class="font-grey-lite">Per Year</span>
</td>
<td class="text-center" id="course_button" onload="check_course(<?php echo $user['id']?>);">
<div id="added_course<?php echo $user['id']?>"><br/><button type="button" class="btn btn-primary" onClick="delete_course_list(<?php echo $user['id']?>);">
<i class="fa fa-star" aria-hidden="true"></i> Course Added</button></div>
<div id="add_course<?php echo $user['id']?>">
<br/><button type="button" class="btn btn-primary"
onClick="save_course_list(<?php echo $user['id']?>);">
<i class="fa fa-star-o" aria-hidden="true"></i> Add to My Course</button></div>
</td>
</tr>
<tr class="row_univ tr_bgs">
<td colspan="6">
<table class="table no-border no-margin text-grey">
<tbody>
<tr class="tr_bgs">
</tr>
</tbody>
</table>
</td>
</tr>
<?php
}
} ?>
</tbody>
</table>
</div>
编写脚本
function check_course(variable)
{
var course_id=str;
var per_email= '<?php echo $per_email; ?>' ;
var datas="&course_id="+course_id+"&per_email="+per_email;
alert(datas);
$.ajax({
type: "POST",
url: 'php/country/check_course.php',
data:datas
}).done(function( data )
{
alert(data);
if(data>0)
{
$('#added_course'+str).show();
$('#add_course'+str).hide();
}
else
{
$('#add_course'+str).show();
$('#added_course'+str).hide();
}
});
}
我犯的错误是这个有语法问题。请帮帮我。提前谢谢。
您应该在body标记中调用onload()
函数
或使用JavaScript
<script>
window.onload = function() {
// functions
}
// or
document.addEventListener("DOMContentLoaded", function() {
// functions
});
</script>
您不能使用onload函数来表使用以下结构
<body onload="check_course(variable);">
//your table
</body>
我遇到了同样的问题,并在使用window.onload函数中检索的自定义属性时找到了解决方案。在我的页面中,我使用了<tr>
元素,但这也适用于<td>
。
表中:
<table>
<tr name="my_row" foo="value1"><td>value1</td></tr>
<tr name="my_row" foo="value2"><td>value2</td></tr>
</table>
在window.onload函数中:
window.onload = function bar() {
var rows = document.getElementsByName("my_row")
for (row in rows) {
var foo = row.getAttribute("foo")
if (foo == "value1") {
// Do something
}
}
}
相关文章:
- 在phonegap中为android调用onload函数的最佳方式
- 将函数从onclick修改为onload
- 如何调用表td标记内的Onload函数
- 不执行包含的页面的Javascript onload函数
- 你能停止window.onload函数吗
- 无法将java脚本函数与Panel'绑定;s OnLoad事件
- 使用多个JavaScript Onload函数
- body onLoad未调用动态生成的javascript函数
- 将函数分配给Reader.onload
- 如何只使用一次window.onload函数
- 在iframe中禁用onload函数的Javascript
- 调用了javascript函数onload并单击按钮
- 触发具有$this的Jquery函数.onload和onclick
- 函数onload()拒绝运行
- 切换到为窗口上的对象分配函数.Onload而不是显式加载.经历困难
- 外部JS函数onload与用户函数onload冲突
- 如何运行一个没有窗口的函数.onload包装
- 同时调用ajax函数onload和onclick
- jquery悬停函数onLoad在firefox中不起作用
- 我如何运行一个函数onload,然后从onclick事件再次调用它