开发者

Passing the name of the link when clicked

开发者 https://www.devze.com 2023-01-04 05:04 出处:网络
I have the following code <a href=\"process.html\">cholera</a> I want to pass cholera to process.开发者_如何学JAVAhtml onClick. Is there any way to do that in HTML?

I have the following code

<a href="process.html">cholera</a>

I want to pass cholera to process.开发者_如何学JAVAhtml onClick. Is there any way to do that in HTML?

If no, PHP scripts are also most welcome.


In pure HTML, only by pre-populating the link with the correct value:

<a href="process.html?name=cholera">cholera</a>

for anything that fetches the link's contents automatically, you would have to use JavaScript. This is comparably easy to do in jQuery. (Update: @James M presents a simple and nice non-jQuery solution in his answer.)

On the receiving end, though, you are going to need some kind of server language (or JavaScript) to do anything with the passed argument.


<a href="process.html?foo=cholera">cholera</a>


index.php

<html>
<body>
<?php
  $values = array('cholera', 'chlamydia'); // dynamic
  foreach($values as $value) echo '<a href="process.php?value=' . $value . '">' . $value . '</a>' . '<br />';
?>
</body>
</html>

process.php

<html>
<body>
<?php
  $value = !isset($_GET['value']) ? 'none' : $_GET['value'];
?>
Value received: <?php echo $value; ?>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消