javascript - タグでhrefとonclickを同時に使用するには?
6 に答える
2
何かのようなもの:
<a href="javascript:void()" title="" onclick="javaScript:showRegisterRules('register.php');">Register</a>
function showRegisterRules(url)
{
alert("Registration Rules");
//Go to your url
document.location.href=url;
}
于 2013-10-26T07:16:49.053 に答える
2
JS
<script type="text/javascript">
function showRegisterRules()
{
alert("Registration Rules");
}
</script>
HTML
<a href="register.php" title="" onclick="showRegisterRules();">Register</a>
于 2013-10-26T07:17:03.937 に答える
2
たったひとつの質問
スクリプトタグにjavascriptを入れましたか?これをしたらうまくいったので
<a href="register.php" title="" onclick="javaScript:showRegisterRules();">Register</a>
JS
<script>
function showRegisterRules()
{
alert("Registration Rules");
}
</script>
于 2013-10-26T07:21:55.633 に答える
1
これを試して:
<a href="#" title="" onclick="javaScript:showRegisterRules();window.location.href='register.php'">Register</a>
于 2013-10-26T07:16:54.130 に答える
1
You can actually write a generic method here rather than one spessific to any given URL.
<a href="register.php" title="" onclick="showRegisterRules(this);">Register</a>
function showRegisterRules(a)
{
alert("Registration Rules");
document.location.href=a.href;
}
This way, you can reuse the same method anywhere within the site to show the alert. This allowing it to go in a script file rather than the html page
于 2013-10-26T07:20:37.823 に答える
1
これもできます
<a href="register.php" title="" onclick="return showRegisterRules('register.php');">Register</a>
function showRegisterRules(url)
{
alert("Registration Rules");
return true;
}
于 2013-10-26T07:26:41.057 に答える