js如何传递参数??????
JScript code
function parseMoulde(xmlDoc) {
......
var aa = kkobj.getAttribute("a");
var bb = kkobj.getAttribute("b");
str1 += "<tr onclick='openWin();'><td>" + aa + "</td><td>" + bb + "</td></tr>";
}
var Win;
function openWin() {
if (Win == null) {
var inner = "<div id=\"yyDiv\">";
Win = new ......
}
$("#yyDiv").html();
Win.open();
}
请教如何传参数aa和bb到新窗口里的div;
?
------解决方案--------------------str1 += "<tr onclick='openWin(\""+aa+"\",\""+bb+"\");'><td>" + aa + "</td><td>" + bb + "</td></tr>";
function openWin(aa,bb) {
$("#yyDiv").html("aa=" + aa +" bb=" + bb);
}
------解决方案--------------------function parseMoulde(xmlDoc) {
......
var aa = kkobj.getAttribute("a");
var bb = kkobj.getAttribute("b");
str1 += "<tr onclick='openWin(aa,bb);'><td>" + aa + "</td><td>" + bb + "</td></tr>";
}
var Win;
function openWin(aa,bb) {
if (Win == null) {
var inner = "<div id=\"yyDiv\">";
Win = new ......
}
$("#yyDiv").html();
var url="page.aspx?arg1="+aa"&arg2="+bb";
Win.open(url);
}
------解决方案--------------------function parseMoulde(xmlDoc) {
......
var aa = kkobj.getAttribute("a");
var bb = kkobj.getAttribute("b");
str1 += "<tr onclick='openWin(\""+aa+"\",\""+bb+""\");'><td>" + aa + "</td><td>" + bb + "</td></tr>";
}
var Win;
function openWin(aa,bb) {
alert(aa+","+bb);
if (Win == null) {
var inner = "<div id=\"yyDiv\">";
Win = new ......
}
$("#yyDiv").html();
Win.open();
}
写法不是很好,参数直接写到字符串里面,也就是写死了,一直都只能是生成字符串时的那个值,而不是点击时实时获取的值。不过如果不是动态的参数也无所谓了
------解决方案--------------------jQuery:
function parseMoulde(xmlDoc) {
......
var aa = kkobj.getAttribute("a");
var bb = kkobj.getAttribute("b");
var $tr = $("<tr><td>" + aa + "</td><td>" + bb + "</td></tr>");
$tr.click(function(){
openWin(aa,bb);
});
}
var Win;
function openWin(aa,bb) {
//aa,bb已经可以用了,根据需要放置到div里
if (Win == null) {
var inner = "<div id=\"yyDiv\">";
Win = new ......
}
$("#yyDiv").html();
Win.open();
}