Javascript问题 [英] Javascript problem

查看:56
本文介绍了Javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,任何人都可以帮帮我..


我有一些td元素有以下ID

ctl1_lnkPrint

ctl2_lnkPrint

ctl3_lnkPrint

ctl4_lnkPrint

ctl5_lnkPrint

...

.. 。

...


我只知道lnkPrint,所以我必须使用通配符...

(类似于* lnkPrint)


我想用html

文件中的上述序列id捕获所有TD元素(使用getElementbyID ... 。)并用

空白td元素替换那些td元素...


任何人都可以给我上面场景的javascript ....


在此先感谢

Meehir

Hello, can any body help me out..

I have some td element which have following ids
ctl1_lnkPrint
ctl2_lnkPrint
ctl3_lnkPrint
ctl4_lnkPrint
ctl5_lnkPrint
...
...
...

and i just know the "lnkPrint", so i have to use wildcard characters...
(something like *lnkPrint)

I want to trap all TD elements with the above sequence id from the html
document (using getElementbyID....) and replace those td element with
blank td element...

Can anybody give me javascript of above scenario....

Thanks in Advance
Meehir

推荐答案

我******** @ gmail.com 写道:
你好,可以任何身体帮助我出去..

我有一些td元素有以下ids
ctl2_lnkPrint
ctl3_lnkPrint
ctl5_lnkPrint
..
..
..

和我只知道lnkPrint,所以我必须使用通配符...
(类似* lnkPrint)

我想用上面的序列id捕获所有TD元素html
文件(使用getElementbyID ....)并用
空白td元素替换那些td元素...

任何人都可以给我上面的场景javascript ... 。

在此先感谢
Meehir
Hello, can any body help me out..

I have some td element which have following ids
ctl1_lnkPrint
ctl2_lnkPrint
ctl3_lnkPrint
ctl4_lnkPrint
ctl5_lnkPrint
..
..
..

and i just know the "lnkPrint", so i have to use wildcard characters...
(something like *lnkPrint)

I want to trap all TD elements with the above sequence id from the html
document (using getElementbyID....) and replace those td element with
blank td element...

Can anybody give me javascript of above scenario....

Thanks in Advance
Meehir



Meehir


那些Id'看起来很asp .net给我!


可以将这些Id'写入你的

代码隐藏的javascript变量中。由于这是一个javascript小组,我不会进入太多

详细信息。作为旁注,这是我停止使用

asp.net的原因之一。


------------- ---- C#CODE -----------------


string cJavascript =" var aIDs = [" ;;


//此时你需要循环使用Serverside对象和

//使用他们的.ClientID attrib构建一个表示
$ b的字符串$ b // javascript数组。即var cIDs = [''foo'',''bar''];"


//然后将其添加到页面

this.Page.RegisterClientScriptBlock(" uniqueServerS ideKey","< script

type = \" text / javascript \">" + cJavascript +"< /脚本>");


-------------------------------- -----------


这会将数组添加到页面中。所以你可以循环浏览

数组来获取你的元素。


----------------- JS代码-----------------


for(var i = 0; i< aIDs.length; i ++)

{

var eElement = document.getElementById(aIDs [i]);

}


--- ----------------------------------------

说完了可以使用javascript获取它们。


如果包含的表格中包含您可以使用的ID:


var etable = document.getElementsById(" IdOfTable");

var aCells = etable.getElementsByTagName(" td");


这将返回表格的所有单元格都可以应用

逻辑,以确保您拥有正确的元素,然后用它们做你想要的



HTH


Andy


Meehir

Those Id''s look very asp.net to me!

It''s possible to write those Id''s to a javascript var from your
codebehind. As this is a javascript group I will not go into too much
detail. As a side note this is one of the reasons i stopped using
asp.net.

----------------- C# CODE -----------------

string cJavascript = "var aIDs = [";

// at this point you need to cycle through your Serverside objects and
// using their .ClientID attrib build a string that represents a
// javascript array. i.e. "var cIDs = [''foo'', ''bar''];"

// Then add it to the page
this.Page.RegisterClientScriptBlock("uniqueServerS ideKey", "<script
type=\"text/javascript\">" + cJavascript + "</script>");

-------------------------------------------

This will add the array to the page. So you could cycle through the
array to obtain your elemnts.

----------------- JS CODE -----------------

for( var i = 0; i < aIDs.length; i++ )
{
var eElement = document.getElementById(aIDs[i]);
}

-------------------------------------------
Having said that it is possible to obtain it them using just javascript.

If the containing table has an ID that you know you could use :

var etable = document.getElementsById("IdOfTable");
var aCells = etable.getElementsByTagName("td");

This will then return ALL the cells of the table that you can apply
logic to in order to ensure you have the correct elements and then to do
what you want with them.

HTH

Andy


嗨Andy,


我对你不是100%满意解决方案,

因为我已经提到我不知道td元素的确切ID。


我事先知道id的后期部分(例如。 ltPrint of ctl2_lnkPrint)

我希望通过循环扫描某些文档的innerhtml部分

并找到那些以lnkPrint作为后缀的td元素。


因为我不能使用服务器端代码,所以我不会从你的任何好处中获益。

C#的解决方案。


实际情况是:

--------------------

i我从第1页导航到第2页,在第2页我正在显示一些HTML

第2页第1页的部分

lblData.innerhtml = window.document.getelementbyid(id).innerhtml


但是这个HTML,我不想显示一些td元素与

lnkPrint作为后缀。


为此,我想扫描该文档的innerhtml部分通过

循环找到那些以lnkPrint作为后缀的td元素。

Hi Andy,

I am not 100% satisfied with ur solution,
as i have mentioned that i dont know the exact id of td element.

I just know later part of id in advance (eg. lnkPrint of ctl2_lnkPrint)
and i want to scan the innerhtml part of some document through the loop
and find those td element with lnkPrint as suffix.

As I cant use server side code, so i dont take any benefit of ur
solution of C#.

Actual scenario is:
--------------------
i am navigating from page1 to page2, in page2 i am showing some html
section of page1 in page2 by
lblData.innerhtml = window.document.getelementbyid(id).innerhtml

But out of this html, i dont want to display some td element with
lnkPrint as suffix.

For that, i want to scan the innerhtml part of that document through a
loop and find those td element with lnkPrint as suffix.


我******** @ gmail.com 写道:
me********@gmail.com wrote:
我从page1导航到第2页,在第2页我显示第2页第1页的html
部分由
lblData.innerhtml = window.document.getelementbyid(id).innerhtml


这个看起来很奇怪,语法不正确,建议您从同一页面获取

数据,而不是从不同的文档中获取。你在使用

帧吗?如果不是如何从第一个文档导入节点?

但是在这个html中,我不想显示一些带有
lnkPrint作为后缀的td元素。

为此,我想通过
循环扫描该文档的innerhtml部分,并找到那些以lnkPrint作为后缀的td元素。
i am navigating from page1 to page2, in page2 i am showing some html
section of page1 in page2 by
lblData.innerhtml = window.document.getelementbyid(id).innerhtml
This looks strange, the syntax isn''t correct and suggests you get your
data from the same page and not from different documents. Are you using
frames? If not how do you import the nodes from the first document?
But out of this html, i dont want to display some td element with
lnkPrint as suffix.

For that, i want to scan the innerhtml part of that document through a
loop and find those td element with lnkPrint as suffix.




我'我不确定是否了解你的场景,但检查

以下是否对你有所帮助 - 它举例说明了一些DOM方法(replaceChild,

getElementsByTagName,createElement)并介绍了regexp找到你要找的

元素。

---

< style type =" text / css" >

表{

border:thin#dd8 groove;

}

td {

保证金:1px;

背景颜色:#ffc;

border:solid 1px#dd8;

font-family: Garamond;

宽度:3em;

身高:3em;

text-align:center;

}

td:悬停{

border:solid 1px yellow;

}

< / style>


< table>

< tbody>

< tr>

< td id =" 1_lnkPrint"> Luffy< ; / td>

< td id =" 2_lnkPrint"> Zoro< / td>

< / tr>

< ; tr>

< td id =" 3_foo"> Nami< / td>

< td id =" 4_lnkPrint"> Sanji< / td> ;

< / tr>

< / tbody>

< / table>


< form action =" foo">

< input type =" button"值= QUOT; FOO()" onclick =" foo()">

< / form>

< script type =" text / javascript">

函数foo(){

if(

document.createElement&&

document.getElementsByTagName& &

document.replaceChild

){


var td = document.getElementsByTagName(" td"); //或其他容器

for(var ii = td.length; ii--;){

if(/ lnkPrint



I''m not sure to have understood your scenario, but check whether the
following does help you - it exemplifies some DOM methods (replaceChild,
getElementsByTagName, createElement) and introduces a regexp to find the
elements you''re looking for.
---
<style type="text/css">
table {
border:thin #dd8 groove;
}
td {
margin:1px;
background-color:#ffc;
border: solid 1px #dd8;
font-family:Garamond;
width:3em;
height:3em;
text-align:center;
}
td:hover {
border: solid 1px yellow;
}
</style>

<table>
<tbody>
<tr>
<td id="1_lnkPrint">Luffy</td>
<td id="2_lnkPrint">Zoro</td>
</tr>
<tr>
<td id="3_foo">Nami</td>
<td id="4_lnkPrint">Sanji</td>
</tr>
</tbody>
</table>

<form action="foo">
<input type="button" value="foo()" onclick="foo()">
</form>

<script type="text/javascript">
function foo(){
if(
document.createElement &&
document.getElementsByTagName &&
document.replaceChild
){

var td=document.getElementsByTagName("td"); // or another container
for(var ii=td.length; ii--;) {
if(/lnkPrint


这篇关于Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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