我一直在思考/寻找下面我遇到的问题,而且找不到任何东西.
有没有办法可以重写这个以与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 =“请求(这)与我的jQuery一起工作.
解决方法
您的问题(标题)的答案是替换
- document.getElementById('about').href = '#';
同
- $('#about').attr('href','#');
我不知道这是否真的会帮助你解决问题,因为我真的不知道你想要做什么.根据您的评论和代码示例,您似乎正在尝试执行某种向导,但我不知道在您发布的内容后它将如何实际工作.
更新:
也许是这样的:
- <a href="link.PHP?test=true" onclick="request(this)" target="_blank" class='request'></a>
- <a id="step2" href="next.PHP">Step 2</a>
- <script language="javascript">
- $(function() {
- var requests = 16;
- $('#step2').click( function() {
- alert('Not finished');
- return false;
- });
- $('.request').click( function() {
- var $this = $(this); // save jQuery reference to element clicked
- // swap indicator image source
- $this.find('img:first').attr('src','images/clear.gif');
- // if the number of flipped indicators equals the number of requests
- // remove the click handler from the step 2 link
- // this removes the alert and allows the user to proceed
- if ($('.request img[src="images/clear.gif"]').length == requests) {
- $('#step2').unbind('click');
- }
- ...do something with the href for this request via ajax???
- // replace this handler with one that simply returns false
- // and remove the href since we're done with this request
- $(this).unbind('click').attr('href','#').click( function() { return false; } );
- // stop the default action for the request
- return false;
- });
- </script>