简体   繁体   English

使用php动态创建html元素并使用javascript进行分页

[英]dynamic creation of html elements using php and doing pagination using javascript

I am creating a element dynamically in html and want to use it in a javascript function by referring to its ID. 我正在用html动态创建一个元素,并希望通过引用其ID在javascript函数中使用它。 But as its ID is dynamically generated using PHP , so how do i pass it to the javascript function into getElementById ? 但是由于其ID是使用PHP动态生成的,因此如何将其传递给javascript函数进入getElementById

Actually , i am trying to do pagination using javascript. 实际上,我正在尝试使用javascript进行分页。 I have displayed Page No.s, and put HREF on them, but onclick function am stuck up? 我已经显示了页码,并在它们上面放了HREF,但是onclick函数卡住了吗? Please help. 请帮忙。 My code is as below: 我的代码如下:

<?php
echo 'Page';

while($d>0)
           {
?>
<input type="hidden" value="<?php echo $z; ?>"  name="pagination" id="<?php echo 'pagination' .$z ; ">

<label id="<?php echo 'labelofpagination'.$z; ?>" >

<a href="#" onclick="PaginationLabelClicked(); submit();" >
<?php echo $z; ?>
</a>

    </label>

<?php
            $z++;
            }

 ?>

in your javascript functio you can use the same PHP expression to get the id 在您的javascript函数中,您可以使用相同的PHP表达式获取ID

var id="<?php echo '\"' .$z '\"'; >";

or you can have it like this, 或者你可以像这样

<script type="text/javascript" language="javascript">
<!--
<?php 
echo("id= $z;");

?>
// -->
</script>

to get the id 获取ID

<label id="<?php echo 'labelofpagination'.$z; ?>" >

<a href="#" onclick="PaginationLabelClicked('<?php echo "\"" ."labelofpagination".$z ."\""; ?>'); submit();" >
<?php echo $z; ?>
</a>

    </label>

and javascript 和JavaScript

function PaginationLabelClicked(id){
// you can get the id here...

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM