将“document.getElementById”转换为进入 jQuery
我一直在思考/寻找与下面遇到的问题相同的问题,但什么也没找到。 有没有办法可以重写它以使用 jQuery 作为替代方案?
代码的前半部分。
<a href="link.php?test=true" onclick="request(this)" target="_blank">
<a id="step2" href="javascript:alert('NOT FINISHED!');">
代码的后半部分。
<script language="javascript">
var requests = 16;
function request(self)
{if(self.href != "#")
requests -= 1;
self.childNodes[0].src = "images/clear.gif";
if(requests === 0)
document.getElementById("step2").href = "next.php";}
</script>
而我想做一个 jQuery var 请求类型的事情。我希望 onclick="request(this)
与我的 jQuery 一起使用。
I've been thinking/searching for an equivalent of the problem that I am having below, and nothing could be found.
Is there a way I can rewrite this to work with jQuery as an alternative?
First half of the code.
<a href="link.php?test=true" onclick="request(this)" target="_blank">
<a id="step2" href="javascript:alert('NOT FINISHED!');">
Second half of the code.
<script language="javascript">
var requests = 16;
function request(self)
{if(self.href != "#")
requests -= 1;
self.childNodes[0].src = "images/clear.gif";
if(requests === 0)
document.getElementById("step2").href = "next.php";}
</script>
Whereas I want to do a jQuery var request type thing. I want onclick="request(this)
to work with my jQuery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样?我想我错过了/不明白一些事情......
Like this? I think I'm missing/not understanding something though...
为了方便起见,您可以在 $ 对象上定义一个附加方法,
然后只需将所有调用从 更改为
。
这有很多注意事项,但根据您的情况,它可能很有用。
For convenience you can define an additional method on the $ object
you can then just change all of your calls from
to
There are tons of caveats with this but it can be useful depending on your situation.
这?不确定我完全明白你想要的
调用方式:
This? Not sure I fully get what you want
invoked by:
你的问题(标题)的答案是替换
为
“我不知道这是否真的能帮助你解决你的问题”,因为我真的不知道你想做什么。根据您的评论和代码示例,您似乎正在尝试执行某种向导,但根据您发布的内容,我不知道它实际上如何工作。
更新:
也许是这样的:
The answer to your question (title) is to replace
with
I have no idea if this will actually help you solve your problem, though, since I really don't know what you are trying to do. Based on your comments and code sample, it appears that you are trying to do some sort of wizard, but I have no idea how it would actually work given what you've posted.
Update:
Maybe something like: