我有一个脚本,其功能是拥有多个jquery弹出框。它通过字符串和ID获取div。这是Javascript ...
function POPUP(string,id){
var closebtn = '<img src="i/JqueryClose.png" onClick="CLOSEPOP('+id+')" title="Close" class="close">';
$('closebtn'+id).css('{margin: -30px -30px 0 0}');
$('#Popup'+id).html(closebtn+id);
$('#Popup'+id).fadeIn(300);
onLoad: true;
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(300);
$('#mask').fadeTo("slow",0.8);
}
function CLOSEPOP(id){
$('#Popup'+id).html('');
$('#Popup'+id).fadeOut(300);
$('#mask').fadeOut(300);
}
//if mask is clicked
$('#mask').click(function () {
$(this).fadeOut(300);
$('.VPopWin').fadeOut(300);
});
现在这里是HTML onclick和div。
<td class="BroadcastText" onClick="POPUP('Popup',1)">Broadcast 1 Message</td>
<div id="Popup1" class="VPopWin">
弹出功能有效,但是当我点击“广播1消息”时,该框只显示div id,在这种情况下是1.如果我点击div id =“Popup2”显示2.我将如何修复此问题显示我的内部而不是ID?
答案 0 :(得分:0)
我更改了您的代码以使其正常工作:
HTML:
<table>
<tr>
<td data-message="test string" class="BroadcastText">Broadcast 1 Message</td>
</tr>
</table>
CSS:
#mask {
z-index: 1000;
display: none;
position: fixed;
background-color: black;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.popup {
position: fixed;
top: 100px;
left: 100px;
z-index: 10001;
color: white;
}
JS:
$(function () {
var body = $('body'),
$document = $(document),
$window = $(window);
var closebtn = $('<img src="i/JqueryClose.png" title="Close" class="close">');
closebtn.css('{margin: -30px -30px 0 0}');
var mask = $('<div id="mask">');
body.append(mask);
$('.BroadcastText').click(POPUP);
function POPUP() {
var string = $(this).data('message');
var popup = $('<div>').addClass('popup');
body.append(popup);
var clbutton = closebtn.clone();
popup.append(clbutton);
clbutton.click(CLOSEPOP);
mask.one('click', CLOSEPOP);
var poptext = $('<div>').html(string);
popup.append(poptext);
popup.fadeIn(300);
//transition effect
mask.fadeIn(300);
mask.fadeTo("slow", 0.8);
function CLOSEPOP() {
popup.fadeOut(300, function () {
popup.remove();
});
mask.fadeOut(300);
}
}
});