简体   繁体   中英

Calling javascript variable parameters from global function on the <a href > onclick even

I am desparate now to find a solution to this problem. I'm trying to call a function on the onclick even inside another function. The event works fine if the parameters are static. I want to get a the value from the global function. The example is as follows:

var dataxml = unescape(xml);    
var xmldoc = getDomAdapter().parseXml(dataxml);
var rootnode = xmldoc.getElementsByTagName('result_set')[0];
var newsresult = rootnode.getElementsByTagName('item');
var pages = Math.round(newsresult.length / 10);

for (var p=1; p <= pages;p++){
    pagesref = pagesref+"<a  href='#' onclick='newsdatainfo(xmldoc,newsresult,6,10);' >"+p+"</a> | ";
}

How do I get the xmldoc and newsresult to be identified? Because I get an undentified error message.

I will be greatfull if you help me.

Did you try "document.xmldoc"?

What scopes are the variable definitions in? If they are private (within a function), they will not be visible from outside that function. In this case, you would need to make them either global (put them into the document's scope), or create closures for your onclick handlers.

You could also try observing the click event (choose favorite framework here).

Prototype: $(ele).observe('click').newsdatainfo() and refactoring the scope of things might make the code cleaner and easier to maintain.

if you are mixing HTML and Javascript, you are usually on the wrong track.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM