Javascript OnClick功能不起作用

时间:2013-05-11 16:17:00

标签: javascript jquery html onclick

重写完整的Javascript。

的Javascript

<div id="PopUp1" style="display: none; color: #FFFFFF;"></div>
<div id="Mask"></div>
<script type="text/javascript">
var Design = '<p>Design!!!!!</p><input type="submit" value="Close" onClick="Close(Design,1)" />';

function PopUp(htmlstring, id) {
    $('#PopUp' + id).fadeIn('slow');
    $('#Mask').fadeIn('slow');
}

function Close(htmlstring, id) {
    $('#PopUp' + id).fadeOut('slow');
    $('#Mask').fadeOut('slow');
}

$('#Mask').click(function () {
    $('#Mask').fadeOut('slow');
    $('#PopUp' + id).fadeOut('slow');
});
</script>

HTML

 <td width="100" align="center" onClick="PopUp(Design,1)">Designs</td>

现在面具显示VAR设计。但是Var没有出现?

3 个答案:

答案 0 :(得分:0)

你正在使用jQuery,$除外。还要确保在<head>中包含jQuery。

function PopUp(htmlstring,id) {
  $('#PopUp'+id).fadeIn('slow');   
  $('#Mask').fadeIn('slow');
}
function Close(htmlstring,id) {
  $('#PopUp'+id).fadeOut('slow');  
  $('#Mask').fadeOut('slow');
}

此外,虽然这无关紧要,但请使用onClick代替onclick

<input type="submit" value="Close" onClick="Close(Design,1)" />

答案 1 :(得分:0)

如果你有jQuery,请一直使用它,只加载一次!!!

使用提交按钮是否有任何特定原因?如果没有,请输入type =“button”

<!DOCTYPE html>
<html>
<head>
<title>Test popup</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
function PopUp(htmlstring,id) {
  $('#PopUp'+id).fadeIn('slow');    
  $('#Mask').fadeIn('slow');
}
function Close(htmlstring,id) {
  $('#PopUp'+id).fadeOut('slow');   
  $('#Mask').fadeOut('slow');
}
$(function() {
  $("#closeButton").on("click",function() {
    Close('Design',1); // not sure what htmlstring is 
  });
  $("#openButton").on("click",function() {
    Popup('Design',1); // not sure what htmlstring is 
  });
});
</script>
</head>
<body>
.
.
.
</body>
</html>

答案 2 :(得分:0)

我不确定我是否正确理解你的问题,但如果我这样做,那么你希望你的变量Design中的文本显示在你的弹出窗口中。

您使用参数htmlstring设置了函数PopUp,但您从未使用它。所以这可能会有所帮助:

function PopUp(htmlstring, id) {
    $('#PopUp' + id).html(htmlstring);
    $('#PopUp' + id).fadeIn('slow');
    $('#Mask').fadeIn('slow');
}