开发者

Conditional Redirection

<a href="/delete/<?php echo $prod_name; ?>" onClick="dropItem()">delete</a>

Now is it true that only if the function dropItem return true will the page be redirected to the url given in the href attribute? If开发者_运维知识库 not then can anyone suggest any method to implement this kind of thing. i.e only when the java script returns true the page redirection happens.


You need to return true or false from within the onclick:

onclick="return dropItem();"

this will indeed stop default link behaviour when false is returned. Only exception: If dropItem() caused an error. In that case, default link behaviour will apply (i.e. the user will be redirected.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜