超链接使用javascript

有时在超链接中需要使用javascript:

<a target=”_blank” href=”#” onclick=”tse()”>学习考试</a>

但这种超链接在点击的时候,会导致本页面刷新。可使用下面方法阻止刷新本页:

<a target=”_blank” href=”javascript:void(0);” onclick=”tse()”>学习考试</a><br />
<script type=”text/javascript”>
function tse(){
var username=’admin’;
username=encodeURI(username);//encode if have non-english characters.
var url = ‘http://127.0.0.1:8080/TSE/loginUser.action?user=

+username+’&password=admin’;

window.open(url,’new’);
return false;
}
</script>

This entry was posted in Computer. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s