Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:invoke<;a/>;表单元格的子元素_Javascript_Jquery_Dhtml - Fatal编程技术网

Javascript jQuery:invoke<;a/>;表单元格的子元素

Javascript jQuery:invoke<;a/>;表单元格的子元素,javascript,jquery,dhtml,Javascript,Jquery,Dhtml,是否可以添加jQuery函数,以便表单元格中的单击将调用 隐藏元素(即TD的后代) 我试过了 $('#表td')。单击(函数(){ $(this.find('a')。单击(); }); 一个其他的变种,但没有运气 --larsw为什么不将JavaScript代码移出href属性并移动到单击事件中?jQuery是用来编写不引人注目的JavaScript的 编辑: 不,但实际上,考虑删除那些隐藏的链接,支持不显眼的JavaScript。以下是重新编写的Corey示例的相关部分: JS: HTML:

是否可以添加jQuery函数,以便表单元格中的单击将调用 隐藏元素(即TD的后代)

我试过了

$('#表td')。单击(函数(){ $(this.find('a')。单击(); });

一个其他的变种,但没有运气


--larsw

为什么不将JavaScript代码移出
href
属性并移动到单击事件中?jQuery是用来编写不引人注目的JavaScript的

编辑:

不,但实际上,考虑删除那些隐藏的链接,支持不显眼的JavaScript。以下是重新编写的Corey示例的相关部分:

JS:

HTML:


a1
a2
b1
b2

为什么不将JavaScript代码从
href
属性中移到单击事件中?jQuery是用来编写不引人注目的JavaScript的

编辑:

不,但实际上,考虑删除那些隐藏的链接,支持不显眼的JavaScript。以下是重新编写的Corey示例的相关部分:

JS:

HTML:


a1
a2
b1
b2

a1
a2
b1
b2
$(函数(){
$('table td')。单击(function(){$(this)。查找('a')。单击()});
})
我有它的工作与上面的剪辑好。但是,请注意jQuery选择器前面有一个#,除非表的id为“table”,否则将失败

话虽如此,可能有一种更好的方法来完成您的任务,而不是隐藏一个嵌入javascript的标签。


a1
a2
b1
b2
$(函数(){
$('table td')。单击(function(){$(this)。查找('a')。单击()});
})
我有它的工作与上面的剪辑好。但是,请注意jQuery选择器前面有一个#,除非表的id为“table”,否则将失败


话虽如此,可能有一种更好的方法来完成您的后续操作,而不是隐藏一个嵌入javascript的标记。

如果您希望避免添加onclick,这将是一种解决方法:

$('#table td').click(function() { 
    $(this).find('a').each(function(){ window.location = this.href; });
});

如果要避免添加onclick,这将是一种解决方法:

$('#table td').click(function() { 
    $(this).find('a').each(function(){ window.location = this.href; });
});

只是一个问题:为什么不让表格单元格内容成为元素(display:block)?只是一个问题:为什么不让表格单元格内容成为元素(display:block)?观察得好。我同意这似乎是问题的根源。它应该是$('表td)。好的观察科里。我同意这似乎是问题的根源。它应该是$('table td)。这对我来说很有帮助。我喜欢在每个元素上避免onclick事件,因此我需要它。它只是起作用了。谢谢这帮我搞定了。我喜欢在每个元素上避免onclick事件,因此我需要它。它只是起作用了。谢谢
<html>
<head></head>
<body>
<table border=1>
    <tr>
        <td>a1<a href=# onclick='alert("a1")' /></td>
        <td>a2<a href=# onclick='alert("a2")' /></td>
    </tr>
    <tr>
        <td>b1<a href=# onclick='alert("b1")' /></td>
        <td>b2<a href=# onclick='alert("b2")' /></td>
    </tr>
</table>
<script src="scripts/jquery-1.2.6.min.js" ></script>
<script>
    $(function(){
        $('table td').click(function(){ $(this).find('a').click()});
    })
</script>
</body>
</html>
$('#table td').click(function() { 
    $(this).find('a').each(function(){ window.location = this.href; });
});