如何选择单击按钮的表格? [英] How to select a table clicking a button?

查看:55
本文介绍了如何选择单击按钮的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每位大师,


我想在页面上放一个按钮。单击按钮时,它下面的

表被选中,因此用户可以执行Ctrl C复制

整个表,而无需使用鼠标选择可以的表

大。我怎么用javascript做到这一点?我试过了:


< INPUT TYPE = Button NAME =''选择''SIZE ='''10''VALUE =''SelctTable''

onClick =" document.MyTable.select();">


< table name = MyTable border = 1>

< tr> < td>这是表< / td>< / tr>

< / table>


我收到错误" document.MyTable是null还是不是对象。


有人可以帮忙吗?提前致谢!


Botao

Hi, Every Guru,

I''d like to put a button on a page. When clicking the button, the
table below it gets selected so the user can do Ctrl C to copy the
entire table without using the mouse to select the table which can be
big. How do I do it using javascript? I tried:

<INPUT TYPE=Button NAME=''Select'' SIZE=''10'' VALUE=''SelctTable''
onClick="document.MyTable.select();">

<table name = MyTable border=1>
<tr><td>This is the table</td></tr>
</table>

I got error "document.MyTable is null or not an object".

Could anyone help please? Thanks in advance!

Botao

推荐答案

Botao写道:
你好,每个大师,

我想在页面上放一个按钮。单击按钮时,它下面的
表被选中,因此用户可以执行Ctrl C复制整个表,而无需使用鼠标选择可能很大的表。我怎么用javascript做到这一点?我试过了:

< INPUT TYPE =按钮NAME =''选择''SIZE ='''10''VALUE =''SelctTable''
onClick =" document.MyTable。 select();">

< table name = MyTable border = 1>
< tr>< td>这是表格< / td>< / tr> ;
< / table>

我收到错误document.MyTable为null或不是对象。

有人可以帮忙吗?提前致谢!
Hi, Every Guru,

I''d like to put a button on a page. When clicking the button, the
table below it gets selected so the user can do Ctrl C to copy the
entire table without using the mouse to select the table which can be
big. How do I do it using javascript? I tried:

<INPUT TYPE=Button NAME=''Select'' SIZE=''10'' VALUE=''SelctTable''
onClick="document.MyTable.select();">

<table name = MyTable border=1>
<tr><td>This is the table</td></tr>
</table>

I got error "document.MyTable is null or not an object".

Could anyone help please? Thanks in advance!




使用"包围属性值。

这样做几乎总是正确的(并且从不错误的afaik)。


< table>没有''name''属性。标记在HTML4.01 w3.org

标准中。改为使用''id'。


DOM Level 2 HTML只为输入和textareas指定select()。

此外,这不会做什么你想要它做什么。


我还没有看到任何标准的Javascript方法来做出选择。


-

Ben M.



Use "" to surround the attribute values. It is almost always correct to
do so (and never incorrect afaik).

There is no ''name'' attribute for the <table> tag in the HTML4.01 w3.org
standard. Use ''id'' instead.

DOM Level 2 HTML only specifies select() for input and textareas.
Furthermore this won''t do what you want it to do.

I have not seen any standard Javascript method of making selections.

--
Ben M.


Botao写道:
Botao wrote:
我想在页面上放一个按钮。单击按钮时,它下面的
表被选中,因此用户可以执行Ctrl C复制整个表,而无需使用鼠标选择可能很大的表。我怎么用javascript做到这一点?


你可以通过使用所谓的范围进行选择,这对IE4 +和Mozilla来说至今支持了b $ b 。复制命令也可以在IE中通过使用execCommand执行,在Mozilla中使用剪贴板执行

帮助程序(但需要更高的安全权限)。

我收到错误document.MyTable为null或不是对象。


那是因为你尝试获取对象的引用方式

是不正确的,看看


< URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html#getEl>

有人可以帮忙吗?提前致谢!
I''d like to put a button on a page. When clicking the button, the
table below it gets selected so the user can do Ctrl C to copy the
entire table without using the mouse to select the table which can be
big. How do I do it using javascript?
You''ll be able to do the selection by using so-called ''ranges,'' which
are so far supported by IE4+ and Mozilla. The copy command can also be
performed, in IE by using execCommand and in Mozilla by using clipboard
helpers (which however require higher security privileges).
I got error "document.MyTable is null or not an object".
That''s because the way you try to get a reference to the table object
isn''t correct, give a look at

<URL:http://www.jibbering.com/faq/faq_notes/alt_dynwrite.html#getEl>
Could anyone help please? Thanks in advance!




< table id =" trainOfThought">

< tr>< td> As am Am< ; / td>< / tr>

< tr>< td>这个垂死的灵魂< / td>< / tr>

< tr>< ; td>无尽的牺牲< / td>< / tr>

< tr>< td>尊敬你的父亲< / td>< / tr>

< tr>< td> Vacant< / td>< / tr>

< tr>< td>意识流< / td>< / tr>

< tr>< td>以上帝的名义< / td>< / tr>

< / table>


< script type =" text / javascript">

var Utils = {

NOT_SUPPORTED:{},


DOM:{

getElementWithId:function(){

var func = function(){return Utils.NOT_SUPPORTED;}

if(document .getElementById){

func = function(id){

return document.getElementById(id);

}

}其他if(document.all){

func = function(id){

return document.all [id];

}

}

return(this.getElementWithId = func)();

}

},


范围:{

create:function(){

var func = function(){return Utils.NOT_SUPPORTED};

if(document.body&& document.body.createTextRange){

func = function(){return document.body.createTextRange();}

} else if(document.createRange){

func = function(){return document.createRange();}

}

return(this.create = func)();

},

selectNode:function(node,originalRng){

var func = function(){return Utils.NOT_SUPPORTED;};

var rng = this.create(),method ="" ;;

if(rng.moveToElementText)method =" moveToElementText";

否则if(rng.selectNode)method =" selectNode";

if(method)

func = function(node,rng){

rng = rng || Utils.Ranges.create();

rng [方法](节点);

返回rng;

}

返回rng = null,(this.selectNode = func)(node,originalRng);

}

},


选择:{

clear:function(){

var func = function(){return Utils.NOT_SUPPORTED};

if(typeof document。 selection!=" undefined"){

func = function(){

if(document.selection&& document.selection.empty){

return(Utils.Selection.clear = function(){

if(document.selection)

document .selection.empty();

})();

}

}

}否则如果( window.getSelection){

var sel = window.getSelection();

if(sel.removeAllRanges){

func = function() {

window.getSelection()。removeAllRanges();

}

}

sel = null;

}

返回(this.clear = func)();

},

add:function(originalRng) ){

var func = function(){return Utils.NOT_SUPPORTED};

var rng = Utils.Ranges.create();

if(rng.select){

func = function(rng){rng.select();}

} else if(window.getSelection){

var sel = window.getSelection();

if(sel.addRange){

func = function(rng){window.getSelection()。addRange (rng);}

}

sel = null;

}

return(this.add = func )(原稿($)
}

};


(function(){

var rng = Utils.Ranges.create();

var ele = Utils.DOM.getElementWithId(" trainOfThought");

if(b) rng!= Utils.NOT_SUPPORTED&& ele!= Utils.NOT_SUPPORTED){

document.write(

"< form>" +

"< input type =''button''value =''选择!''onclick =''" +

" Utils.Selection.clear();" +

" Utils.Selection.add(" +

" Utils.Ranges.selectNode(" +

" Utils.DOM.getElementWithId(\") ; trainOfThought \")" +

")" +

")" +

"'' >" +

"< \ / form>"

);

}

))();

< / script>

HTH

是的。



<table id="trainOfThought">
<tr><td>As I Am</td></tr>
<tr><td>This Dying Soul</td></tr>
<tr><td>Endless Sacrifice</td></tr>
<tr><td>Honor Thy Father</td></tr>
<tr><td>Vacant</td></tr>
<tr><td>Stream Of Consciousness</td></tr>
<tr><td>In The Name Of God</td></tr>
</table>

<script type="text/javascript">
var Utils = {
NOT_SUPPORTED : {},

DOM : {
getElementWithId : function() {
var func=function(){return Utils.NOT_SUPPORTED;}
if(document.getElementById) {
func=function(id){
return document.getElementById(id);
}
} else if(document.all) {
func=function(id) {
return document.all[id];
}
}
return (this.getElementWithId=func)();
}
},

Ranges : {
create : function() {
var func=function(){return Utils.NOT_SUPPORTED};
if(document.body && document.body.createTextRange) {
func=function(){return document.body.createTextRange();}
} else if(document.createRange) {
func=function(){return document.createRange();}
}
return (this.create=func)();
},
selectNode : function(node, originalRng) {
var func=function(){return Utils.NOT_SUPPORTED;};
var rng=this.create(), method="";
if(rng.moveToElementText) method="moveToElementText";
else if(rng.selectNode) method="selectNode";
if(method)
func=function(node, rng){
rng=rng||Utils.Ranges.create();
rng[method](node);
return rng;
}
return rng=null,(this.selectNode=func)(node, originalRng);
}
},

Selection : {
clear:function() {
var func=function(){return Utils.NOT_SUPPORTED};
if(typeof document.selection!="undefined") {
func=function(){
if(document.selection && document.selection.empty) {
return (Utils.Selection.clear=function(){
if(document.selection)
document.selection.empty();
})();
}
}
} else if(window.getSelection) {
var sel=window.getSelection();
if(sel.removeAllRanges) {
func=function(){
window.getSelection().removeAllRanges();
}
}
sel=null;
}
return (this.clear=func)();
},
add : function(originalRng) {
var func=function(){return Utils.NOT_SUPPORTED};
var rng=Utils.Ranges.create();
if(rng.select) {
func=function(rng){rng.select();}
} else if(window.getSelection) {
var sel=window.getSelection();
if(sel.addRange) {
func=function(rng){window.getSelection().addRange( rng);}
}
sel=null;
}
return (this.add=func)(originalRng);
}
}
};

(function() {
var rng=Utils.Ranges.create();
var ele=Utils.DOM.getElementWithId("trainOfThought");
if(rng!=Utils.NOT_SUPPORTED && ele!=Utils.NOT_SUPPORTED) {
document.write(
"<form>"+
"<input type=''button'' value=''Select!'' onclick=''"+
"Utils.Selection.clear();"+
"Utils.Selection.add("+
"Utils.Ranges.selectNode("+
"Utils.DOM.getElementWithId(\"trainOfThought\" )"+
")"+
")"+
"''>"+
"<\/form>"
);
}
})();
</script>
HTH
Yep.


是的,


非常感谢您的回复。 范围太差了。仅在

IE4中支持。所以我猜IE5中没有办法做选择。使用

javascript。


Botao
Yep,

Thanks much for your reply. Too bad the "range" is only supported in
IE4. So I guess there is no way in IE5 to do "selecting" using
javascript.

Botao


这篇关于如何选择单击按钮的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆