jQuery 在输入中更改 document.location.href
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6602720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery change document.location.href in input
提问by user832375
is it possible to use jQuery to do that:
是否可以使用 jQuery 来做到这一点:
if the body has a <div id="wpadminbar">
then change the document.location.href in this input from
如果正文有一个<div id="wpadminbar">
则更改此输入中的 document.location.href
<input type="button" onclick="document.location.href='/wp-login.php?action=register';" value="Forum" id="forum">
to
到
<input type="button" onclick="document.location.href='/forum';" value="Forum" id="forum">
回答by Naftali aka Neal
if($('#wpadminbar').length > 0) {
$('#forum').attr('onClick', "document.location.href='/forum';");
}
回答by Kyle Hotchkiss
You may want to do this in Javascript alone. Instead of changing the links there, try this:
您可能只想在 Javascript 中执行此操作。不要改变那里的链接,试试这个:
<script type="text/javascript">
$(document).load(function() {
$("#forum").click(function() {
document.location.href="your URL";
});
});
</script>
If you can, place that in your <head>
如果可以的话,把它放在你的 <head>
回答by brenjt
Try
尝试
jQuery("#forum").attr("onclick", "document.location.href='/forum'");