English 中文(简体)
不能获得“how光”干 the法
原标题:Can not get the javascript "show hide" div code to work

I CANNOT在该项目上使用j Query(客户政策)。

我的html法典是:

<div style="display:none" id="dvAnswer<%#Eval("num")%>" class="TextFontBold">A: <%#Eval("answer") %></div>
<a id="btn<%#Eval("num")%>" href="javascript:toggle();">show answer</a>  

海关编码是:

    function toggle() {
            var ele = document.getElementById("toggleText");
            var text = document.getElementById("displayText");
            if(ele.style.display == "block") {
                ele.style.display = "none";
                text.innerHTML = "show";
            }
            else {
                ele.style.display = "block";
                text.innerHTML = "hide";
            }
    }   

I cannot get this code to work.
Any suggestions to resolving this?

最佳回答

这里,你需要两处提及你的角逐功能,一则提及目标,一则提及:

<div style="display:none" id="dvAnswer<%#Eval("num")%>" class="TextFontBold">A: <%#Eval("answer") %></div>
<a id="btn<%#Eval("num")%>" href="javascript://" onclick="toggle( dvAnswer<%#Eval("num")%> ,this);">show answer</a>

(此外,使用<代码>onclick,而不是href,用于在线javascript)

接着提及你的职能:

function toggle(target,me) {
            var ele = document.getElementById(target);
            var text = me
            if(ele.style.display == "block") {
                ele.style.display = "none";
                text.innerHTML = "show";
            }
            else {
                ele.style.display = "block";
                text.innerHTML = "hide";
            }
    }     
问题回答

贵要素的识别符号不是toggleText,我也不见displayText

首先,您的四分之四有:<0>toggleText>,无> > > >

因此,你需要做的是为此创造小算法。

function toggle(lnk) {
           var num = lnk.getAttribute( id ).toString().replace( btn ,  );
            var ele = document.getElementById( dvAnswer +num);
            if(ele.style.display == "block") {
                ele.style.display = "none";
                lnk.innerHTML = "show";
            }
            else {
                ele.style.display = "block";
                lnk.innerHTML = "hide";
            }
    } 

阁下,

<div style="display:none" id="dvAnswer<%#Eval("num")%>" class="TextFontBold">A: <%#Eval("answer") %></div>
<a id="btn<%#Eval("num")%>" onclick="toggle(this); return false;" href="#">show answer</a> 

看来,你用错误的身份证来找人。 在你的超文本中,我看不到你的任何要素的角逐或显示Text ID。

国际发展研究中心从你的例子中看到活力。 也许只是通过你的职能中的标语:

function toggle(objRef) {
        var ele = document.getElementById(objRef);
        var text = document.getElementById("displayText");
        if(ele.style.display == "block") {
            ele.style.display = "none";
            text.innerHTML = "show";
        }
        else {
            ele.style.display = "block";
            text.innerHTML = "hide";
        }
}

传真:

<a id="btn<%#Eval("num")%>" href="javascript:toggle("dvAnswer<%#Eval("num")%>");">show answer</a>

或许你在html上的id与javascript的要求不一样? 这种“应当”的工作

<div style="display:none" id="toggleText" class="TextFontBold">A:<%#Eval("answer") %></div>
<a id="displayText" href="javascript:toggle();">show answer</a>  




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签