채택완료

팝업창에 버튼값 넘기는 방법좀 알려쥬세요

2021-12-21 (화) 18:23:27 3,631

<button type="button" onclick="javascript:play();" onfocus="this.blur()" title="" data-ch="standard">버튼</button>

<script>
function play(){
    var ch = $(this).attr('data-ch');
    window.open('/index.php?ch='+ch, 'plyer', 'left=100,top=100,width=500,height=600,scrollbars=0,location=no,toolbar=no,menubar=no,resizable=no'); 
}
</script>

저 파라미터값 ch에 버튼의 data-ch값을 넣고 싶은데 방법은 잘못됐는지 안되네요.

부탁드립니다.

|

답변 2개 / 댓글 1개

채택된 답변
+20 포인트
2021-12-22 (수) 14:28:47

$(this)를 찍어보세요. 아무것도 안나오지 않나요?

접근방식을 바꾸셔서 

Copy
<button type="button" class="btn2" title="" data-ch="standard">버튼2</button>

$(document).on("click", ".btn2", function() {
  var ch;
  ch = $(this).data("ch");
  alert(ch);
});

해보시면 가능할 겁니다

2021-12-21 (화) 18:28:23
Copy
var ch = $(this).data('ch');

window.open('/index.php?ch='+ch+'plyer','left=100,top=100,width=500,height=600,scrollbars=0,location=no,toolbar=no,menubar=no,resizable=no');

답변에 대한 댓글 1개

안되네요 파라미터값 ch에 undefined만 찍혀나옵니다.
사실 .data('ch'); 안되서 attr로 한거입니다. ㅜㅜ

답변을 작성하려면 로그인이 필요합니다.