Javascript 转换;document.getElementById";进入jQuery
我一直在思考/寻找下面我遇到的问题的等价物,但什么也找不到。 有没有一种方法可以重写它,以使用jQuery作为替代方案 代码的前半部分。Javascript 转换;document.getElementById";进入jQuery,javascript,jquery,function,href,Javascript,Jquery,Function,Href,我一直在思考/寻找下面我遇到的问题的等价物,但什么也找不到。 有没有一种方法可以重写它,以使用jQuery作为替代方案 代码的前半部分。 <a href="link.php?test=true" onclick="request(this)" target="_blank"> <a id="step2" href="javascript:alert('NOT FINISHED!');"> <script language="javascript"> var
<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>
代码的后半部分。
<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>
var=16;
功能请求(self)
{if(self.href!=“#”)
请求-=1;
self.childNodes[0].src=“images/clear.gif”;
如果(请求===0)
document.getElementById(“step2”).href=“next.php”;}
而我想做一个jqueryvar请求类型的事情。我想
onclick=“request(this)
处理我的jQuery。像这样?我想我遗漏了/不理解一些东西
$('#about').click( function(evt) {
request(this);
});
这个?我不确定我能完全得到你想要的
function request(element)
{
$(element).doSomething();
return false;
}
由以下人员调用:
onclicked="return request(this);"
您的问题(标题)的答案是替换
document.getElementById('about').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>
$(函数(){
var=16;
$('#步骤2')。单击(函数(){
警报(“未完成”);
返回false;
});
$('.request')。单击(函数(){
var$this=$(this);//将jQuery引用保存到单击的元素
//交换指示器图像源
$this.find('img:first').attr('src','images/clear.gif');
//如果翻转指示器的数量等于请求的数量
//从步骤2链接中删除单击处理程序
//这将删除警报并允许用户继续
if($('.request img[src=“images/clear.gif”]')。length==请求){
$('步骤2')。解除绑定('单击');
}
…使用href通过ajax对此请求执行操作???
//将此处理程序替换为仅返回false的处理程序
//并删除href,因为我们已完成此请求
$(this).unbind('click').attr('href','#')。click(function(){return false;});
//停止请求的默认操作
返回false;
});
为了方便起见,您可以在$object上定义一个附加方法
$.getElementById = function(id){
return $('#'+id).get(0);
};
然后,您可以将所有电话从
document.getElementById
到
这方面有很多警告,但根据您的情况,它可能会很有用。请求它?它是什么?链接处的页面?为什么不完全删除锚定标签,这样他们就不能点击它?更改href非常简单,但我不知道您真正想做什么。也许可以解释一下您正在尝试的内容完成这项任务会有所帮助。仅仅更改href作为一项操作似乎毫无意义。我有5个按钮,我希望在每次点击按钮时,它都会请求它,这样在满足请求后,它会更改href以表示“id(about)”。目前href=”#“可以这么说,允许他们不继续进行吗?你能给出一个关于警告的提示吗