2009-11-17 4 views
0

빌드하지 않은 웹 사이트를 확장합니다. ShowWindow proc를 매개 변수로 호출 할 수 있기를 원합니다. 내가 어떻게 그럴 수 있니? JQuery와 Javascript를 처음 사용함.자바 호출 기능

default.aspx 

<script type="text/javascript" src="/scripts/jquery-1.2.6.js"></script> 
<script type="text/javascript"> 

$(document).ready(function() { 
    $('a#ShowWindow').click(function() { 
     window.open("TerminalInfo.aspx?", 'Info', 'scrollbars=yes,width=510,height=536'); 
    }) 
}); 

하여 default.aspx.cs

동적으로 영문을 구축 ...

public static string ToHtml(this Location location) 
    { 
     var html = new StringBuilder(); 

     html.Append("<td><a href='#' id='ShowWindow'>ShowLetter</a></td>");    //This works 
     html.Append("<td><a href='#' id='ShowWindow(\"MyInfo.aspx\")'>Read More</a></td>"); //How can I do this? It doesn't work. 

     return html.ToString(); 
    } 
+1

(테이블에 여러 링크 작업은) 나에게 보이는 당신이 이해하지 못하는 코드를 작성하는있다. 적재 된 총으로 놀고 있니? –

+1

@Josh Stodola : JavaScript는로드 된 총보다 약간 안전합니다. 그리고 모두는 어딘가에서 배우기 시작해야합니다. –

+0

조쉬의 요점은 그가 코딩을 시작하고 rtfm에 대한 근면을하기 전에 질문을하는 것처럼 보인다고 생각합니다. JavaScript의 이벤트는 지나치게 문서화됩니다. –

답변

6
public static string ToHtml(this Location location) 
{ 
    var html = new StringBuilder(); 

    html.Append("<td><a href='MyInfo.aspx' id='ShowWindow'>Read More</a></td>"); 

    return html.ToString(); 
} 

다음

,
$('a#ShowWindow').click(function(e) { 
    window.open($(this).attr("href"), 'Info', 'scrollbars=yes,width=510,height=536'); 
    e.preventDefault(); 
}) 

다소 다른 접근 방식이지만 JavaScript를 사용할 수없는 경우 성능이 떨어집니다.

업데이트

$('table a').click(function(e) { 
    window.open($(e.target).attr("href"), 'Info', 'scrollbars=yes,width=510,height=536'); 
    e.preventDefault(); 
}); 
+1

+1 그리고 onclick 속성을 사용하지 않는 유일한 해결책입니다. 나는 믿음을 잃기 시작했다. –

+0

예, 제 것보다 낫습니다. 내 것은 단순히 명백한 오류에 응답하고있었습니다. 그가이 프로젝트에서 JavaScript를 배우려고한다면 우리는 그가 올바르게 배울 수 있도록 도와야한다고 생각합니다. – sheats

+0

내가보기에 유일한 문제는 false를 반환하지 않으므로 페이지가 변경되어 – Shawn

-2
var strattonn = {}; 
strattonn.openWindow = function(url, title) { 
    window.open(url, title, 'scrollbars=yes,width=510,height=536'); 
    return false; 
} 


public static string ToHtml(this Location location) 
{ 
    var html = new StringBuilder(); 
    html.Append("<td><a href='#' onclick='return strattonn.openWindow('MyInfo.aspx', 'My Info')'>Read More</a></td>"); 
    return html.ToString(); 
} 
+0

좋아요. 그래서 onclick 속성은 나쁜 습관입니다; p – Shawn